我想得到以下结果:
__ _ __ _ __ _ __ _ ___ _页面标题
因此,假设 html 标记是<h1>Title of page</h1>
并且 h1 设置为width:100%
and text-align:right
,我希望它只在标题的左侧加下划线。
任何线索如何做到这一点?我试图将标题包装在 a 中<div>
,给它一个白色背景并将其向下移动一点,因此它与 h1 框的底部重叠,但是,我不知道这是否 100% 跨浏览器有效。
替代解决方案:
<div style="width:100%;float:left;border-bottom:1px solid">
<h1 style="float:right;background-color:white;padding:1px;position:relative;top:1px">Hola</h1>
</div>
看起来你正在尝试做的事情会更好地通过包装容器和内部浮动来实现。使内部 div(或浮动 h1)具有白色背景。使外部 div 具有与文本 div 的 line-height 相同的间距的重复(repeat-y)背景。
确保包装器 div 尊重浮动 div(溢出:隐藏或在浮动末尾有一个清晰的 div。
这将为您提供您正在寻找的效果,并且也应该与多行标题一起使用。
我会使用 CSS 生成的内容,带有不间断的空格和下划线:http: //jsfiddle.net/JMVUa/1/
h1:before{
content:"\a0\a0\a0\a0\a0\a0\a0\a0\a0\a0\a0\a0\a0";
text-decoration: underline;
}