我是最少使用图像的忠实粉丝,并且想知道是否有人使用纯静态CSS创建这种类型的策略(或者是否可能)?
http://www.flickr.com/photos/jahimandahalf/6780397612/
我指的是一条似乎越来越瘦的线条效果以及阴影效果。
我当时认为用三角形做一个CSS形状技巧是可能的:
http://css-tricks.com/snippets/css/css-triangle/
或许可以使用'transform'在box-shadow上旋转:
zenelements.com/blog/css3-transform /
有什么想法吗?
答案 0 :(得分:16)
您可以使用CSS3的停靠点和:after
伪元素来实现此类效果。诀窍是使用<hr>
伪元素为:after
元素添加边框,并将其放置在初始渐变的中心,并使用以渐变结束的柔和颜色。
答案 1 :(得分:5)
好的,所以我已经回答了我自己的问题,但我已经阅读了Stackoverflow论坛,这似乎是可以接受的(如果不是真的鼓励了!)
因此...
<强> 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 */
}
答案 2 :(得分: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>
答案 3 :(得分:4)
为了重现该水平线,您可以使用CSS3线性渐变。只需创建一个高度约为3px的div并应用以下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
不支持色卡,因此您可能希望图像回落为&lt; IE10。
在此处构建您自己的CSS3渐变:http://www.colorzilla.com/gradient-editor/
答案 4 :(得分:0)
此代码创建一个正常的hr但不同之处在于它将以淡入淡出效果结束(渐变黑色到蓝色)
hr{
border-top-color: black;
margin-bottom: 25px;
width: 80%;
}
hr::before{
display: block;
margin-left: -10%;
margin-top: -1px;
content:"";
background: linear-gradient(to left, black, blue);
width: 10%;
height: 1px;
}
hr::after{
display: block;
margin-left: 100%;
margin-top: -1px;
content:"";
background: linear-gradient(to right, black, blue);
width: 10%;
height: 1px;
}