3

Wired 的移动视图(将您的用户代理设置为 iOS Safari 以在桌面上查看)对标准带下划线的超链接样式进行了优雅的改动:

在此处输入图像描述

我认为这纯粹是由没有外部图形的 CSS 实现的,但不是:

background-image: url(http://cdn.mobify.com/sites/wired/production/i/link-bg.png);
background-size: 5px 24px;

我很清楚使用该border属性来创建自定义加权下划线,但无法创建线底切,因为margin-bottom在到达文本基线时偏移会切断。

仅使用 CSS 可以实现这种样式吗?

4

3 回答 3

8

您可以应用inset box-shadow属性:

a {
    text-decoration: none;
    color: #000;
    box-shadow: inset 0 -4px 0 #c0e6f7;
}

jsFiddle 演示

第一个值是inset,它使box-shadow向内,而不是向外(因为没有更好的方法来放置它),第二个值0是 x 值(从一边到另一边的盒子阴影)。接下来-4px是 y 值(从上到下)。第三个是0让阴影没有“模糊”效果(从而给你一个实心边框效果),然后是颜色值。:)

于 2014-01-04T02:08:17.340 回答
1

我喜欢@JaceCotton 的回答,但缺少 WIRED 在其图像版本中的一些小细节。细节,例如下划线底部的稍深的蓝色线和下划线的软顶部。

这些细节可能并不重要或不那么引人注目,但我认为这些微小的细节确实有助于原始 WIRED 版本的标记下划线效果。

只需将此 css 添加到任何 a 标签即可查看效果(演示):

background: -moz-linear-gradient(top,  rgba(255,255,255,0) 0%, rgba(198,232,248,0) 75%, rgba(192,230,247,1) 83%, rgba(192,230,247,1) 94%, rgba(184,226,245,1) 95%, rgba(184,226,245,1) 97%, rgba(184,226,245,0) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,0)), color-stop(75%,rgba(198,232,248,0)), color-stop(83%,rgba(192,230,247,1)), color-stop(94%,rgba(192,230,247,1)), color-stop(95%,rgba(184,226,245,1)), color-stop(97%,rgba(184,226,245,1)), color-stop(100%,rgba(184,226,245,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  rgba(255,255,255,0) 0%,rgba(198,232,248,0) 75%,rgba(192,230,247,1) 83%,rgba(192,230,247,1) 94%,rgba(184,226,245,1) 95%,rgba(184,226,245,1) 97%,rgba(184,226,245,0) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  rgba(255,255,255,0) 0%,rgba(198,232,248,0) 75%,rgba(192,230,247,1) 83%,rgba(192,230,247,1) 94%,rgba(184,226,245,1) 95%,rgba(184,226,245,1) 97%,rgba(184,226,245,0) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  rgba(255,255,255,0) 0%,rgba(198,232,248,0) 75%,rgba(192,230,247,1) 83%,rgba(192,230,247,1) 94%,rgba(184,226,245,1) 95%,rgba(184,226,245,1) 97%,rgba(184,226,245,0) 100%); /* IE10+ */
background: linear-gradient(to bottom,  rgba(255,255,255,0) 0%,rgba(198,232,248,0) 75%,rgba(192,230,247,1) 83%,rgba(192,230,247,1) 94%,rgba(184,226,245,1) 95%,rgba(184,226,245,1) 97%,rgba(184,226,245,0) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#00b8e2f5',GradientType=0 ); /* IE6-9 */
于 2014-01-24T18:32:49.423 回答
1

您可以使用线性渐变和背景大小来做到这一点。

演示

a {
  text-decoration: none;
  color: inherit;
  background: linear-gradient(to bottom, rgb(227,244,251), rgb(175,221,243)) bottom repeat-x;
  background-size: 25%;
}
于 2014-01-04T02:20:11.020 回答