Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

Where in the CSS specs does it say how multiple properties with the same name should be handled?

In debugging another issue, I'd like to confirm I've correctly understood how a browser should handle a declaration like

background-image: url(image0.jpg);
background-image: image-set(url(image1.jpg) 1x, url(image2.jpg) 2x);

I've poked around in the specs a little but couldn't find it.

My impression from testing it out is that browsers will go with the first declaration they consider valid, but I would like to confirm this with a source. Note that I'm not (just) asking what the correct behaviour is – I'm specifically looking for an authoritative source, ideally a spec.

question from:https://stackoverflow.com/questions/66063087/where-in-the-css-specs-does-it-say-how-multiple-properties-with-the-same-name-sh

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To answer my own question – I realised I should probably look for the answers to the two sub-questions "which out of two declarations wins" and "what should it do about invalid declarations".

For the former, https://www.w3.org/TR/css-cascade-3/#cascade-order says

The last declaration in document order wins.

which I take to mean that out of two property-value declarations with the same property, the last one wins.

And for the latter, https://www.w3.org/TR/css-cascade-3/#w3c-partial says

user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.

which I take to mean that if a browser e.g. doesn't support image-set in the question's example, it will ignore that entire declaration.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...