html - CSS:文本位于所选颜色的基线上

标签 html css text typography

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

但是,尽管我的结果给出了我想要的效果,但有些东西告诉我有一种更简单的方法可以达到相同的效果。

如有任何建议,我们将不胜感激。

这个 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;
} 

screenshot of what i currently see in firefox & chrome

最佳答案

这是另一种方式,添加一个额外的跨度: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;
}

喂, -泰德

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

关于html - CSS:文本位于所选颜色的基线上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22255671/

相关文章:

python - 从文件中提取与另一个文件中的条件匹配的某些行

css - 可滚动的固定形式显示在左侧

javascript - 从页面中删除其他元素后为 float 元素设置动画

jquery - 表单提交时的沙漏

jquery - 如何以 3 行排列图像 div?

html - 是否可以使用 CSS 在单行中指定所有属性(顶部、底部、左侧、右侧)

c - 从 C 中的文本文件中读取 8 位二进制数

javascript - 如何在 JavaScript 中制作计时器?

jquery - Bootstrap 中输入字段的边框

css - 文本 css 背景就像是手工完成的一样