我已经看到有关使用 JavaScript 检测和处理溢出 HTML 元素的文本的建议。但现在是 2013 年,所以我想知道 CSS 规范是否有办法自行检测溢出。
换句话说,如果我有一个固定大小的 div:
<div class="smart-warning" style="width:200px; height:20px; overflow:hidden">
This is my very long text that would overflow the box.
</div>
如果文本溢出,我想要一种样式,例如:
<style>
.smart-warning {
border:1px solid black
}
.smart-warning:overflowing {
border:1px solid red
}
</style>
看起来我们真的很接近在 CSS 中拥有类似的东西,但倾注规范不是我的游戏。
如果它不存在,你认为它有用吗?
谢谢!