Is there a CSS selector for an IMG which has been

2019-02-18 11:23发布

问题:

If I define the following CSS rule:

img {
    max-width:  200px;
    max-height: 200px;
    border: 1px solid black;
}

Is there a pure-CSS way of detecting those image objects that would have been larger without the size constraints? Something that semantically matches:

img:resized {
    border-color: green;
}

Alternatively: is there a way of only detecting large images in the first place? For example:

img {
    border: 1px solid black;
}
img[width>200px], img[height>200px] {
    max-width:  200px;
    max-height: 200px;
    border-color: green;
}

Thanks!

回答1:

No, there are no CSS selectors that can query style properties, whether declared or computed, as rendering of DOM elements has no relation to the DOM hierarchy.