用CSS淡出边框

时间:2013-04-29 22:19:39

标签: css

我的页脚有一个虚线的顶部边框,如下所示:

footer 
{
    border-top:1px dashed #ddd;
    color:#999;
}

我想知道如何让虚线从左到右淡出。谢谢!

2 个答案:

答案 0 :(得分:8)

可能有一个更简单的解决方案,但一个是放置一个从左到右覆盖边界的渐变,例如。

footer:before {
    content: "";
    background-color: black;
    height: 1px;
    display: block;
    top: -1px;
    position: relative;
    background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%);
}

http://jsfiddle.net/tcs6J/1/

答案 1 :(得分:4)

您可以使用CSS Gradients创建此项。检查here

为了使其尽可能简单,首先要创建两个div:

<div id="borderbox">
    <div id="box">
    </div>
</div>

我们将使用外框并为其赋予渐变背景,然后为内部div提供白色背景,从而伪造边框。

#borderbox {
    background-color: #eee; /* fallback color if gradients are not supported */
    background-image: -webkit-linear-gradient(to right, #000, #fff); /* For Chrome and Safari */
    background-image:    -moz-linear-gradient(to right, #000, #fff); /* For old Fx (3.6 to 15) */
    background-image:     -ms-linear-gradient(to right, #000, #fff); /* For pre-releases of IE 10*/
    background-image:      -o-linear-gradient(to right, #000, #fff); /* For old Opera (11.1 to 12.0) */
    background-image:         linear-gradient(to right, #000, #fff); /* Standard syntax; must be last */    
    width: 500px;
    height: 200px;
    display: block;
    padding: 1px 0 0 0;
    opacity: 0.5;
    border-top: 1px dashed #ccc;
}
#box { background: #fff; width: 500px; height: 200px;  margin-top: -1px; }

演示:http://jsfiddle.net/XwJEB/1