带有透明度渐变的虚线下划线链接样式

4
我希望用一种从100%不透明度到0%的点状渐变来强调我的链接。我制作了一个截图,如下所示: dotted links 我想做的是:
a {
  border-bottom: 2px dotted #007acc;
} 

但是没有渐变到0不透明度的颜色,单个点之间的间距太小了。
关于这个问题的另一个问题:我有一些:before内容('+'),我不希望border-bottom碰到那个内容,就像您看到的那样。
这是否可能,或者我必须使用png背景?
Jquery也可以。

在WebKit中可以实现渐变边框,我猜您可以使用这里的帮助来实现您想要的效果 http://css-tricks.com/examples/GradientBorder/ - aroundtheworld
谢谢您提供的链接,确实是我们所使用的。 - sqe
2个回答

4

这里有一个快速的例子,不确定它是否符合您的需求。

body{
    background:#111;
}
ul{
    padding:0;
    margin:0;
}
li{
    margin-left:20px;
    width:200px;
    list-style:none;
    border-bottom:dotted 2px #99f;
    color:#99f;
    position:relative;
}
li:before{
    content:'+';
    position:absolute;
    left:-15px;
}
li:after{
    content:'';
    position:absolute;
    height:2px;
    width:100%;
    top:100%;
    background:red;
    left:0;

background: -moz-linear-gradient(left, rgba(17,17,17,0) 0%, rgba(17,17,17,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(17,17,17,0)), color-stop(100%,rgba(17,17,17,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(17,17,17,0) 0%,rgba(17,17,17,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(17,17,17,0) 0%,rgba(17,17,17,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(17,17,17,0) 0%,rgba(17,17,17,1) 100%); /* IE10+ */
background: linear-gradient(to right, rgba(17,17,17,0) 0%,rgba(17,17,17,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00111111', endColorstr='#111111',GradientType=1 ); /* IE6-9 */
}

http://jsfiddle.net/KZPbf/

实用的跨浏览器渐变生成器:http://www.colorzilla.com/gradient-editor/


这是一个有趣的概念。 - Vinny Fonseca
@VinnyFonseca 除了生成一系列具有不同背景颜色的单个DOM对象之外,我想不到其他办法了。 :) - Andy
谢谢,这正是我一直在寻找的!确实是一个有趣的概念。 - sqe

1
你可以使用带有线性渐变背景的伪元素覆盖在边框上方。
a {
  border-bottom: 2px dotted #007acc;
}
a:after {
  content: '';
  display: block;
  position: absolute;
  width: 100%;
  height: 2px;
  top: 100%;
  background: linear-gradient(left, rgba(22, 23, 25, 1) 0%, rgba(22, 23, 25, 0) 100%);
}

你的背景颜色可能需要保持不变,但这应该能达到效果。根据你计划支持的浏览器,你仍然需要使用厂商前缀和正确的颜色代码。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接