"Fade" Borders in CSS

Fade borders in CSS

You can specify gradients for colours in certain circumstances in CSS3, and of course borders can be set to a colour, so you should be able to use a gradient as a border colour. This would include the option of specifying a transparent colour, which means you should be able to achieve the effect you're after.

However, I've never seen it used, and I don't know how well supported it is by current browsers. You'll certainly need to accept that at least some of your users won't be able to see it.

A quick google turned up these two pages which should help you on your way:

  • CSS3 Gradient Borders
  • http://designshack.co.uk/tutorials/introduction-to-css3-part-2-borders

Hope that helps.

how to fade-out/blur div's borders with css?

box-shadow IS actually the only CSS way to get this effect. Try something like this:

div {  margin: 25px 10px;  width: 100px;  height: 100px;  background: #141414;  box-shadow: 0 0 15px 10px #141414;}
<div></div>

Fade in border on hover

When an element has no border, then you add on hover you face a few issues such as page moving, drawing border from scratch etc

Solution: Try setting border to transparent first, so it's there but cannot be seen:

a {     border-bottom: 2px solid transparent; /* <- here */    transition: border-bottom 1s;    text-decoration: none; /* I added this for clarity of effect */}a:hover {    border-bottom: 2px solid red;}
<a href="">testing border</a>

CSS fading top and bottom borders

Do you want something like this?

Demo (Some breathing space for your content, I've used margin there, just make sure that it will apply to both, :before as well as :after, so if you want to separate, declare margin separately for each, p.s - I've made colors lil lighter)

/* Using only background gradients */

.one {
width: 400px;
padding: 20px 25px;
margin: 40px auto;
}

.one:before, .one:after {
content: "";
height: 1px;
/* I've removed the vendor prefixes, if you are looking to support older browsers
then refer to older version of this answer.
*/
background: linear-gradient(to right, rgba(0,0,0,0) 0%,rgba(147,147,147,1) 50%,rgba(0,0,0,0) 100%);
display: block;
margin-bottom: 10px;
margin-top: 10px;
}

Explanation:
I've used :before and :after pseudo having content: "", so it creates a block, you can say a virtual block inside the element... and which is further set to display: block, just make sure you use block there else margins and height will have no effect.. and last but not the least am using gradients with rgba to control the alpha/opacity of the gradient which will fade on both ends

Fading a border (css)

You can use two fade-out images as background-image

li.edge_top, li.edge_bottom {
background-position: right;
background-repeat: no-repeat;
}

li.edge_top {
background-image: url:('fadeout_top.png');
}

li.edge_bottom {
background-image: url:('fadeout_bottom.png');
}

Circle with fading borders on the bottom

You could use a pseudo element with an inset box-shadow to create the fade out border on the bottom like this :

body {
background: #232323;
}

.wrap {
box-sizing: border-box;
position: relative;
width: 50%;
border: 3px solid #ffd004;
border-radius: 50%;
}

.wrap::before {
content:'';
display:block;
padding-bottom:100%;
}

.wrap::after {
content: '';
position: absolute;
bottom: -3px;
left: -3px;
right: -3px;
height: 100%;
z-index: 1;
box-shadow: inset 0px -270px 70px -100px #232323;
}

.title {
color: #ffd004;
margin: 0;
position: absolute;
top: -3px;
left: 0;
width: 100%;
text-align: center;
z-index: 2;
background: #232323;
}

.circle {
position: absolute;
top:15%;
left:15%;
width: 70%;
height: 70%;
border-radius: 50%;
background: #ffd004;
z-index: 2;
}
<div class="wrap">
<h2 class="title">Title</h2>
<div class="circle"></div>
</div>

Fade a css border to invisible?

Something like this ?

div.transition {
border: 5px solid rgba(0,0,0,1);
height: 100px;
width: 100px;
background-color: #ffffff;

-webkit-transition: border-color 1s linear; /* Saf3.2+, Chrome */
-moz-transition: border-color 1s linear; /* FF3.7+ */
-o-transition: border-color 1s linear; /* Opera 10.5 */
transition: border-color 1s linear;
}

div.transition:hover {
border-color: rgba(0,0,0,0);
}

Demo at http://jsfiddle.net/gaby/bcn5c/1/

Soft Edges using CSS?

Another option is to use one of my personal favorite CSS tools: box-shadow.

A box shadow is really a drop-shadow on the node. It looks like this:

-moz-box-shadow: 1px 2px 3px rgba(0,0,0,.5);
-webkit-box-shadow: 1px 2px 3px rgba(0,0,0,.5);
box-shadow: 1px 2px 3px rgba(0,0,0,.5);

The arguments are:

1px: Horizontal offset of the effect. Positive numbers shift it right, negative left.
2px: Vertical offset of the effect. Positive numbers shift it down, negative up.
3px: The blur effect. 0 means no blur.
color: The color of the shadow.

So, you could leave your current design, and add a box-shadow like:

box-shadow: 0px -2px 2px rgba(34,34,34,0.6);

This should give you a 'blurry' top-edge.

This website will help with more information: http://css-tricks.com/snippets/css/css-box-shadow/



Related Topics



Leave a reply



Submit