I am doing a gradient border of a div in css3. So far now I have done my coding like this
in css
.bot-left {
position: relative;
}
.bot-left:before, .bot-left:after {
content: "";
position: absolute;
bottom: -3px;
left: -3px;
}
.bot-left:before {
top: -3px;
width: 3px;
background-image: -webkit-gradient(linear, 0 100%, 0 0, from(#000), to(transparent));
background-image: -webkit-linear-gradient(transparent, #000);
background-image: -moz-linear-gradient(transparent, #000);
background-image: -o-linear-gradient(transparent, #000);
}
.bot-left:after {
right: -3px;
height: 3px;
background-image: -webkit-gradient(linear, 0 0, 100% 0, from(#000), to(transparent));
background-image: -webkit-linear-gradient(left, #000, transparent);
background-image: -moz-linear-gradient(left, #000, transparent);
background-image: -o-linear-gradient(left, #000, transparent);
}
in html
<div class="bot-left" style="width: 200px; height: 200px"></div>
But still I am not getting the exact match as reference. The reference image for the gradient border is attached with this
UPDATE
I want the background-color should be transparent.
I would recommend you to use the gradients as background instead of border images. The reason I am suggesting you to use this method is because border-image isn't supported by IE10. Where as you can implement this method to support IE9 as well, by using base64 encoded gradients.
Now, here am using two absolute positioned elements along with :before and :after pseudo elements which are positioned absolute.
Demo
Here, you can refactor this to a great extent, I've not done that so that you can figure out how this works.
Also, if you want, you can wrap this inside a position: relative; container with a negative z-index set on the elements having class of .frame1 and 2 respectively.
Demo 2
body {
background: #000;
}
.frame1,
.frame2 {
position: absolute;
top: 25px;
left: 25px;
bottom: 25px;
right: 25px;
}
.frame1:before {
content: "";
position: absolute;
left: 0;
top: 0;
height: 100%;
background: linear-gradient(to bottom, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
width: 1px;
}
.frame1:after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
background: linear-gradient(to right, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
height: 1px;
}
.frame2:before {
content: "";
position: absolute;
right: 0;
bottom: 0;
height: 100%;
background: linear-gradient(to top, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
width: 1px;
}
.frame2:after {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background: linear-gradient(to left, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%);
height: 1px;
}
For younger browser , you may use one single gradient, box-shadow and transparent border : DEMO
CSS used for demo:
.bot-left {
background:
linear-gradient(
to bottom right,
#777,
#555,
#333,
#111,
#333,
#555,
#777) center;
background-size:105% 105%;/* needs to lay under borders */
box-sizing:border-box;/* keep borders inside width and height setted */
border:1px transparent solid;/* background will show through */
box-shadow:inset 0 0 0 500px black, 0 0 0 5px black;/* inset shadow will hide background gradient */
margin:5px;/* optionnal: includes ouside box-shadow in space needed by element */
}
Related
I have a project where I try to draw a circle with a gradient border. I have made it so it works in Chrome. But the styling doesn't work in safari. I don't know why it wouldn't work. I have added a mask: version for safari.
.gradient-circle {
height: 10rem;
width: 10rem;
--b: 5px;
/* border width*/
display: inline-block;
margin: 10px;
z-index: 0;
position:relative;
}
.gradient-circle:before {
content: "";
position: absolute;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: var(--c, linear-gradient(to top, #5454d4, rgba(249, 116, 104)));
mask: linear-gradient(0deg, #fff, transparent 96%), radial-gradient( farthest-side, transparent calc(100% - var(--b) - 1px), #fff calc(100% - var(--b))) content-box;
-webkit-mask: linear-gradient(0deg, #fff, transparent 96%), radial-gradient( farthest-side, transparent calc(100% - var(--b) - 1px), #fff calc(100% - var(--b))) content-box;
mask-composite: intersect;
-webkit-mask-composite: destination-in;
border-radius: 50%;
padding: 1px;
}
<span class="gradient-circle"></span>
Here is a different idea without mask-composite which is the culprit I guess. Simply consider an extra layer to be able to apply both mask independently
.gradient-circle {
height: 10rem;
width: 10rem;
--b: 5px; /* border width*/
display: inline-block;
margin: 10px;
z-index: 0;
position: relative;
}
.gradient-circle div,
.gradient-circle div:before {
position: absolute;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.gradient-circle div {
-webkit-mask: linear-gradient(0deg, #fff, transparent 96%);
}
.gradient-circle div:before {
content: "";
background: var(--c, linear-gradient(to top, #5454d4, rgba(249, 116, 104)));
-webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--b) - 1px), #fff calc(100% - var(--b))) content-box;
border-radius: 50%;
padding: 1px;
}
<span class="gradient-circle">
<div></div>
</span>
I want to make a div into 2 triangles (as shown in below, no problem if 1 is background of parent) upper one with one color and lower one with another. I dont mind how it is implemented but i want to do it in css (not javascript). I tried with css rotation, (code below), but its not responsive. In smaller or wider screen it is distorted . Any way to implement this in css?
body {
background: #eee;
}
.darker {
position: fixed;
top: -94%;
left: -10%;
width: 150%;
height: 150%;
background: #dd4f39;
-webkit-transform: rotate(30deg);
transform: rotate(30deg);
}
<div class="darker"> </div>
I found an interesting way to do this from here, which uses clip-path
.Answering my own question so that everyone can use it.
html,
body {
margin: 0;
}
body {
background: #eee;
}
.box {
width: 100vw;
height: 100vh;
background-color: #dd4f39;
clip-path: polygon(0 0, 100% 0, 100% 100%);
}
<div class="box"></div>
This is one way of doing it. But this use case is strictly with respect to vw. Just make sure to give the same value to these elements
div and it's pseudo element should have same width and border-left respectively.
div and it's pseudo element should have same height and border-top respectively.
html, body {
margin: 0;
}
.box {
width: 100vw;
height: 100vh;
background-color: white;
}
.box::after {
content: ' ';
border-top: 100vh solid #dd4f39;
border-left: 100vw solid transparent;
width: 0;
position: absolute;
}
<div class="box"></div>
JS fiddle
https://jsfiddle.net/kqsrmrss/2/
You can do that with a skewed pseudo element. The main trick is to keep the aspect ratio the same or else the sloped angle will fail
Fiddle demo
Stack snippet Note 1
body {
background: #eee;
}
.darker {
position: absolute;
top: 0;
left: 0;
width: 100%;
padding-top: 50%;
background: #dd4f39;
overflow: hidden;
}
.darker::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: gray;
transform: skewY(26.5deg);
transform-origin: left top;
}
<div class="darker"></div>
Optionally, you can add media query to control the angle at different screen sizes
Fiddle demo 2
With a tiny script running when window resize's, you can control the angle and make it fully responsive both horizontally and vertically.
Note 1 Based on a comment, the Stack snippet might not work properly, and if, try the fiddle demos.
Please Use this code snippet.
div {
width: 100%;
height: 100px;
}
.diagonalRising {
border: 1pt solid black;
background: linear-gradient(to right bottom, #eeeeee 0%, #eeeeee 49.9%, #eeeeee 50%, #000000 51%, #dd4f39 51.1%, #dd4f39 100%);
}
.diagonalFalling {
background: linear-gradient(to right top, #eeeeee 0%, #eeeeee 49.9%, #000000 50%, #000000 51%, #dd4f39 51.1%, #dd4f39 100%);
}
.diagonalCross {
position: relative;
background: linear-gradient(to right bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 49.9%, rgba(0, 0, 0, 1) 50%, rgba(0, 0, 0, 1) 51%, rgba(0, 0, 0, 0) 51.1%, rgba(0, 0, 0, 0) 100%);
}
.diagonalCross:after {
content: "";
display: block;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
background: linear-gradient(to right top, #ffffff 0%, #ffffff 49.9%, #000000 50%, #000000 51%, #ffffff 51.1%, #ffffff 100%);
}
<div class="diagonalRising"></div>
<div class="diagonalFalling"></div>
<div class="diagonalCross"></div>
Try this,
.box::after {
background: #E52A35
content: '';
position: absolute;
width: 100%;
height: 100vh;
background-color: #dd4f39;
clip-path: polygon(52% 13%, 104% -1%, -1% 0%);
}
Below is the image I am trying for, I managed to get a square using CSS, but I am trying for horizontal and vertical line in a square.
.hub{
width: 119px;
height: 101px;
background: #b5adad;
}
<div class="hub"></div>
There are many ways to do this and one would be to use gradients like below: (the image in question was actually a rectangle.)
The approach is very simple - we use 2 linear gradients to create two thin solid colored lines and then position the images such that they match our needs. Linear gradients are used even though it creates only a solid color because it is easier to control size and position of an image than background color.
div {
height: 100px;
width: 200px;
border: 1px solid red;
background-image: linear-gradient(to bottom, red, red), linear-gradient(to right, red, red);
background-repeat: no-repeat;
background-size: 1px 100%, 100% 1px;
background-position: 20px 0px, 0px 10px;
}
<div></div>
We can also create an output which has a fade-out or shadow effect like in the image in question:
div {
height: 100px;
width: 200px;
border: 1px solid;
background-color: gray;
background-image: linear-gradient(to bottom, black, black), linear-gradient(to right, red, transparent), linear-gradient(to right, black, black), linear-gradient(to bottom, red, transparent);
background-repeat: no-repeat;
background-size: 1px 100%, 1px 100%, 100% 1px, 100% 1px;
background-position: 20px 0px, 21px 0px, 0px 10px, 0px 11px;
box-shadow: inset 0px 0px 3px red;
}
<div></div>
Another way is to use :before and :after pseudo-elements:
.hub{
width: 119px;
height: 101px;
background: #b5adad;
position: relative;
padding: 18px 0 0 18px;
}
.hub:after, .hub:before {
content: " ";
background: black;
display: block;
position: absolute;
}
.hub:after {
width: 1px;
height: 100%;
left: 15px;
top: 0;
}
.hub:before {
width: 100%;
height: 1px;
top: 15px;
left: 0;
}
<div class="hub">Lorem ipsum dolor amet</div>
I'm currently designing a website, and for the footer I've created a "zigzag" border on top.
To create some depth in the website, I wanted to add a drop shadow on the triangles in the "zigzag", and this is where I'm currently stuck.
Here is an example of the footer as I have it right now: http://jsfiddle.net/CwXp4/
body {
background: url(http://i.imgur.com/R1yaNOy.png);
}
#footer {
position: absolute;
width: 100%;
height: 200px;
bottom: 0;
background-color: #333;
}
#footer:before {
content: "";
display: block;
position: relative;
top: -21px;
height: 21px;
background: linear-gradient( 45deg, #333 50%, transparent 50%) 0 0, linear-gradient(-45deg, #333 50%, transparent 50%) 0 0;
background-repeat: repeat-x;
background-size: 40px 40px, 40px 40px;
}
<div id="footer"></div>
Is there someone out there with some tips for me on how to add a drop shadow?
You can somehow make the shadow with the same gradients that you are using to make the zigzag.
CSS
#footer:before {
content: "";
display: block;
position: relative;
top: -21px;
height: 22px;
background: linear-gradient( 45deg, #333 50%, blue 50%, transparent 55%) 0 0,
linear-gradient(-45deg, #333 50%, blue 50%, transparent 55%) 0 0;
background-repeat: repeat-x;
background-size: 40px 47px, 40px 47px;
}
body {
background: url(http://i.imgur.com/R1yaNOy.png);
}
#footer {
position: absolute;
width: 100%;
height: 200px;
bottom: 0;
background-color: #333;
}
#footer:before {
content: "";
display: block;
position: relative;
top: -21px;
height: 22px;
background: linear-gradient( 45deg, #333 50%, blue 50%, transparent 55%) 0 0, linear-gradient(-45deg, #333 50%, blue 50%, transparent 55%) 0 0;
background-repeat: repeat-x;
background-size: 40px 47px, 40px 47px;
}
<div id="footer"></div>
fiddle
You could also get the shadow with a webkit-filter shadow, but this has limited support
CSS
#footer:before {
content: "";
display: block;
position: relative;
top: -21px;
height: 22px;
background: linear-gradient( 45deg, #333 50%, transparent 50%) 0 0,
linear-gradient(-45deg, #333 50%, transparent 50%) 0 0;
background-repeat: repeat-x;
background-size: 40px 47px, 40px 47px;
-webkit-filter: drop-shadow(red 0px -5px 5px);
}
body {
background: url(http://i.imgur.com/R1yaNOy.png);
}
#footer {
position: absolute;
width: 100%;
height: 200px;
bottom: 0;
background-color: #333;
}
#footer:before {
content: "";
display: block;
position: relative;
top: -21px;
height: 22px;
background: linear-gradient( 45deg, #333 50%, transparent 50%) 0 0, linear-gradient(-45deg, #333 50%, transparent 50%) 0 0;
background-repeat: repeat-x;
background-size: 40px 47px, 40px 47px;
-webkit-filter: drop-shadow(red 0px -5px 5px);
}
<div id="footer"></div>
fiddle with filter
Here is my HTML
<div class="about-buttonback"><div class="about-button"></div></div>
Here is the CSS:
.about-button {
color:#fff;
content: "Calender";
Display: block;
position: absolute;
width: 860px;
height: 40px;
top:5px;
left:5px;
text-indent: -9999px;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
background-color: #d1d2d4;
background-image: -webkit-gradient(linear, left top, left bottom, from(#323232), to(#2a2829));
background-image: -webkit-linear-gradient(top, #000, #2a2829);
background-image: -moz-linear-gradient(top, #000, #2a2829);
background-image: -o-linear-gradient(top, #000, #2a2829);
background-image: linear-gradient(to bottom, #000, #2a2829);
box-shadow: 1px 1px 1px #000;
}
.about-buttonback {
display: block;
position: absolute;
width: 870px;
height: 50px;
top:0px;
left: 35px;
text-indent: -9999px;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
background-color: #d1d2d4;
background-image: -webkit-gradient(linear, left top, left bottom, from(#6b6b6b), to(#000));
background-image: -webkit-linear-gradient(top, #4b4b4b, #000);
background-image: -moz-linear-gradient(top, #4b4b4b, #000);
background-image: -o-linear-gradient(top, #4b4b4b, #000);
background-image: linear-gradient(to bottom, #4b4b4b, #000);
}
I am trying to do more over a overlay with a title over the blocks. I need the content to say Calender but it is not showing up over the blocks. Any suggestions?
Thank you so much for the help!
First of all you won't need display: block;, and secondly, you are not able to see the text because you are using text-indent: -9999px which will just move any text in that block out of the viewport.
Demo
Also, make sure you wrap the position: absolute; elements under position: relative; container, else they will mess up your layout.
Do this thing :-
Fiddle
<div class="about-button">Calendar</div>
you need the content to say Calender over the blocks for that if you add any text in Div
let's say "**<div class="about-button">Calendar </div>**" but text will not going to show after this too because you added " text-indent: -9999px; " to the both of the classes which you should need to remove in order to let your text display over the blocks.