Questenaتمرینی که نشان می‌دهد بعد چه چیزی را مرور کنید
سؤال 2

The markup contains <p style='color: blue;'>Hello</p> and the author stylesheet contains: p { color: red !important; } What color is the text, and why?

  1. Blue — a style attribute has the highest possible specificity, so no rule in a stylesheet can override it.
  2. Red — the cascade sorts declarations by origin and importance before anything else, and an important author declaration outranks a normal one, including a normal declaration in a style attribute.پاسخ درست
  3. Blue — !important only changes how a declaration competes with other rules inside stylesheets; it never competes with inline styles.
  4. Red — marking a declaration !important resets the specificity of the competing style attribute to zero.

توضیح

The style attribute does not sit above everything; it sits above normal author rules. The cascade first sorts by origin and importance, and 'important author' is a higher bucket than 'normal author', which is where a plain style attribute participates. So the important declaration in the stylesheet wins and the text is red. Note the symmetry the wrong answers miss: had the inline declaration itself been written as color: blue !important, it would have won, because among important author declarations the style attribute again takes precedence.

ادامهٔ این آزمون

شروع تمرین