【问题标题】:CSS: Text to sit on baseline of chosen colourCSS:位于所选颜色基线上的文本
【发布时间】:2014-04-10 22:18:50
【问题描述】:

在过去,我一直在努力实现让文本位于指定颜色的基线上的效果。今天我有点幸运,取得了一些进展。

然而,虽然我的结果给了我想要的效果,但它告诉我有一种更简单的方法可以达到同样的效果。

任何建议将不胜感激。

这个 JSFiddle 展示了我想要的效果以及我目前实现它的方法。

http://jsfiddle.net/leeboyce/QZ5F5/1/

<h2>
    <span>
         Is there another way to <br /> achieve this effect? <br /><br />Aim:<br /> have different coloured underline sitting on the text baseline
    </span>
</h2>

h2 {
    font-size: 2.4em;
    line-height: 1em;
    color: #f78f1e;
    font-weight: bold;
}
h2 span {
    background-color: transparent;
    background: -webkit-gradient(linear, 0 0, 0 100%, from(#d2d2d2), color-stop(0%, transparent)) 0 1em;
    background: -webkit-linear-gradient(bottom, #d2d2d2 0%, transparent 1px) 0 1em;
    background: -moz-linear-gradient(bottom, #d2d2d2 0%, transparent 1px) 0 1em;
    background: -ms-linear-gradient(bottom, #d2d2d2 0%, transparent 1px) 0 1em;
    background: -o-linear-gradient(bottom, #d2d2d2 0%, transparent 1px) 0 1em;
    background: linear-gradient(bottom, #d2d2d2 0%, transparent 1px) 0 1em;
    -webkit-background-size: 100% 2.4em;
    -moz-background-size: 100% 2.4em;
    -ms-background-size: 100% 2.4em;
    -o-background-size: 100% 2.4em;
    background-size: 100% 2.4em;
} 

【问题讨论】:

  • 在 Chrome 的那个小提琴中看不到任何下划线。我错过了什么吗?
  • 我可以在 Mozilla 中看到下划线,但没有其他 CSS 提示的内容。我们应该看到什么?
  • 无论如何,虽然我仍然不知道你在追求什么,但我很确定跨度的 css 中的 2.4em 是不正确的。除非您的意思是周围文本大小的 5.76 倍。
  • 抱歉 - 我很难说清楚,所以我附上了我目前在 Firefox 和 Chrome 中看到的屏幕截图。重要的是 - 我希望能够控制下划线与文本基线的距离。

标签: html css text typography


【解决方案1】:

这是另一种方式,添加一个额外的跨度:fiddle

<h2>
    <span class="ul">
        <span class="text">Is there another way to <br />
achieve this effect? <br /><br />Aim:<br /> have different coloured 
underline sitting on the text baseline
        </span>
    </span>
</h2>

和 CSS

h2 {
    font-size: 2.4em;
    line-height: .8em;
    color: #f78f1e;
    font-weight: bold;
}
.ul {
    border-bottom:1px solid #cccccc;
}
.text{
    vertical-align:-6px;
}

HTH, -泰德

编辑添加:这是使用 text-decoration:underline css 的第二个小提琴,如果该下划线适合您another fiddle

【讨论】:

  • 感谢@Ted,这看起来正是我想要的。简单得烦人哈哈。
  • 酷...如果这就是您要寻找的内容,请将问题标记为已回答 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-24
  • 2021-03-29
  • 2014-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-31
相关资源
最近更新 更多