2012-02-24 68 views
12

我是一个很少使用图像的狂热粉丝,想知道是否有人有策略(或者如果可能的话)用纯静态CSS创建这种类型的东西?CSS淡出水平规则/线条样式div效果不带图像

http://www.flickr.com/photos/jahimandahalf/6780397612/

我指一条线看似越来越瘦和淡出的效果,它下面的阴影效果。

我想有可能做一个CSS形状招用它像三角形:使用“转换”

http://css-tricks.com/snippets/css/css-triangle/

或许与箱阴影旋转:

zenelements .com/blog/css3-transform/

任何想法?

回答

14

您可以使用CSS3的停止,:after伪元素来实现这样的效果。诀窍是通过使用:after伪元素将边框添加到<hr>元素,并将其放置在初始渐变的中心,并使用渐变结束的柔和颜色。

这是一个快速的demo,和另一个demo使用一些颜色。

+0

嗯非常时尚,谢谢你的答案!我将不得不有一个发挥。 – 2012-02-25 20:27:24

4

为了重现该水平线,您可以使用CSS3线性渐变。只要创建一个div约3px的高度,并应用下面的CSS(改变颜色根据需要):

background: #ffffff; /* Old browsers */ 
background: -moz-linear-gradient(left, #ffffff 0%, #2989d8 25%, #207cca 75%, #ffffff 100%); /* FF3.6+ */ 
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#ffffff), color-stop(25%,#2989d8), color-stop(75%,#207cca), color-stop(100%,#ffffff)); /* Chrome,Safari4+ */ 
background: -webkit-linear-gradient(left, #ffffff 0%,#2989d8 25%,#207cca 75%,#ffffff 100%); /* Chrome10+,Safari5.1+ */ 
background: -o-linear-gradient(left, #ffffff 0%,#2989d8 25%,#207cca 75%,#ffffff 100%); /* Opera 11.10+ */ 
background: -ms-linear-gradient(left, #ffffff 0%,#2989d8 25%,#207cca 75%,#ffffff 100%); /* IE10+ */ 
background: linear-gradient(left, #ffffff 0%,#2989d8 25%,#207cca 75%,#ffffff 100%); /* W3C */ 
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#ffffff',GradientType=1); /* IE6-9 */ 

记住filter不支持彩色停止,所以你可能需要的图像回落的< IE10。

构建自己的CSS3渐变的位置:http://www.colorzilla.com/gradient-editor/

+0

嗯,谢谢你肯定引发了答案,但你也不能令人信服我一直在寻找越来越薄方面,以及(将修改到我原来的职位)。但你给我指路,欢呼。 (对不起,我甚至不能投票给你!不是'nuf rep!) – 2012-02-24 20:49:51

+0

我很高兴你能找到你的答案! – 2012-02-27 13:43:19

5

好了,所以我已经回答了我的问题,但我读过的#1论坛,这似乎是可以接受的(如果不是实际上鼓励!)

所以......

HTML:

<html> 
<head> 
<TITLE>TEST</TITLE> 
<link rel="stylesheet" type="text/css" href="test.css" /> 
</head> 
<body> 

<div id="wrap"> 
<div id="gradient"> 
</div> 
</div> 

</body> 
</html> 

CSS:

#wrap 
{ 
overflow:hidden; 
height:10px; 
width:600px; 
height:20px; 
margin:auto; 
margin-top:200px; 
} 


#gradient 
{ 
height:20px; 
width:580px; 
margin:auto; 
margin-top:-11px; 
background: -moz-radial-gradient(center, ellipse cover, rgba(10,10,10,1) 0%, rgba(8,8,8,1) 19%, rgba(3,3,3,0) 80%, rgba(1,1,1,0) 100%); /* FF3.6+ */ 
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(10,10,10,1)), color-stop(19%,rgba(8,8,8,1)), color-stop(80%,rgba(3,3,3,0)), color-stop(100%,rgba(1,1,1,0))); /* Chrome,Safari4+ */ 
background: -webkit-radial-gradient(center, ellipse cover, rgba(10,10,10,1) 0%,rgba(8,8,8,1) 19%,rgba(3,3,3,0) 80%,rgba(1,1,1,0) 100%); /* Chrome10+,Safari5.1+ */ 
background: -o-radial-gradient(center, ellipse cover, rgba(10,10,10,1) 0%,rgba(8,8,8,1) 19%,rgba(3,3,3,0) 80%,rgba(1,1,1,0) 100%); /* Opera 12+ */ 
background: -ms-radial-gradient(center, ellipse cover, rgba(10,10,10,1) 0%,rgba(8,8,8,1) 19%,rgba(3,3,3,0) 80%,rgba(1,1,1,0) 100%); /* IE10+ */ 
background: radial-gradient(center, ellipse cover, rgba(10,10,10,1) 0%,rgba(8,8,8,1) 19%,rgba(3,3,3,0) 80%,rgba(1,1,1,0) 100%); /* W3C */ 
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0a0a0a', endColorstr='#00010101',GradientType=1); /* IE6-9 fallback on horizontal gradient */ 
} 
5

hr { 
 
    height: 1px; 
 
    margin: 50px 0; 
 
    background: -webkit-gradient(linear, 0 0, 100% 0, from(rgba(0, 0, 0, 0)), color-stop(0.5, #333333), to(rgba(0, 0, 0, 0))); 
 
    background: -webkit-linear-gradient(left, rgba(0, 0, 0, 0), #333333, rgba(0, 0, 0, 0)); 
 
    background: -moz-linear-gradient(left, rgba(0, 0, 0, 0), #333333, rgba(0, 0, 0, 0)); 
 
    background: -o-linear-gradient(left, rgba(0, 0, 0, 0), #333333, rgba(0, 0, 0, 0)); 
 
    background: linear-gradient(left, rgba(0, 0, 0, 0), #333333, rgba(0, 0, 0, 0)); 
 
    border: 0; 
 
} 
 
hr:after { 
 
    display: block; 
 
    content: ''; 
 
    height: 30px; 
 
    background-image: -webkit-gradient(radial, 50% 0%, 0, 50% 0%, 116, color-stop(0%, #cccccc), color-stop(100%, rgba(255, 255, 255, 0))); 
 
    background-image: -webkit-radial-gradient(center top, farthest-side, #cccccc 0%, rgba(255, 255, 255, 0) 100%); 
 
    background-image: -moz-radial-gradient(center top, farthest-side, #cccccc 0%, rgba(255, 255, 255, 0) 100%); 
 
    background-image: -o-radial-gradient(center top, farthest-side, #cccccc 0%, rgba(255, 255, 255, 0) 100%); 
 
    background-image: radial-gradient(farthest-side at center top, #cccccc 0%, rgba(255, 255, 255, 0) 100%); 
 
}
<hr>