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

mag*_*tte 7 html css

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

例如,如果我说:

<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>
Run Code Online (Sandbox Code Playgroud)

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;
}
Run Code Online (Sandbox Code Playgroud)

有没有办法使用纯 CSS 使背景颜色:红色规则仅在文本溢出时适用?

注意:我可以看到一种使用 javascript 执行此操作的方法;我只是想知道是否有一个纯 CSS 的方法来做到这一点。