4

I would like to underline my links with some kind of dotted gradient from 100% opacity to 0%. I made a screen of what I should look like:

dotted links

I would do sth like

a {
  border-bottom: 2px dotted #007acc;
} 

but there is no gradient to 0 opacity and the space between the single dots is way too small.

Another question regarding this problem: I have some :before content (the '+') and I don't want the border-bottom to hit that content, as you can see.

Is this even possible or do I have to use a png background?

Jquery would be ok too.

4

2 回答 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/

于 2013-03-18T20:55:45.690 回答
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%);
}

您的背景可能需要保持相同的颜色,但这应该可以完成工作。根据您计划支持的浏览器,您仍然需要供应商前缀和正确的颜色代码。

于 2013-03-18T20:52:06.147 回答