有没有办法在元素溢出时有条件地将特定样式应用于元素?
例如,如果我说:
<div>
This text is very long, no really it is extremely long; it just goes on and on and on and on. You might say it's a bit like the Duracell(R) bunny, but without the batteries, and the floppy ears.
</div>
和
div {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
// TODO: is there any way to only apply this rule if the text is overflowing?
div {
background-color: red;
}
有没有办法使用纯 CSS 让 background-color: red 规则仅在文本溢出时适用?
注意:我可以看到使用 javascript 执行此操作的方法;我只是想知道是否有一种纯 CSS 方法可以做到这一点。