无论内容如何,我只需要在第一行留下一个词,因此无法进行额外的标记。
我尝试使用伪元素来做到这word-spacing
一点::first-line
。这在 Firefox 或 IE 中运行良好,但在 WebKit 浏览器中失败(在最新版本的 Chrome、Opera 和 Safari 中测试)。
此外,为整个元素设置字间距也可以。
我是否遗漏了某些东西,或者它在 WebKit 中不起作用?
如果在 Firefox 或 IE 中打开,但在 WebKit 浏览器中打开,下面的示例完全符合我的要求。
.outer {
width: 100px;
border: 1px solid black;
height: auto;
margin: 0 0 20px;
}
.inner {
display: inline-block;
}
.with-first-line::first-line {
word-spacing: 200px;
}
.whole {
word-spacing: 200px;
}
<div class="outer">
<span class="inner with-first-line">long line with words</span>
</div>
<div class="outer">
<span class="inner whole">long line with words</span>
</div>