仅当元素溢出时才将特定样式应用于元素

时间:2013-05-09 11:06:21

标签: html css html5 css3

有没有办法在元素溢出时有条件地应用特定样式?

E.g。如果我说:

<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来获得背景颜色:红色规则仅在文本溢出时适用?

注意:我可以通过javascript看到这样做的方法;我只想知道是否有一种纯CSS方式来实现它。

0 个答案:

没有答案