Document Style Sheets Multiple Classes
Multiple Classes: Resolving ‘conflicts’
•
‘Conflicts’ between multiple classes can be resolved in advance by
defining a directive that specifically applies to their combination
Consider the style directives
. re d1 . blue { color : wh ite ; background - color : or an ge ; }
. re d1 { co lor : red ; background - color : ye llow ; ma rgin : 5 px ; }
. bl ue { co lor : blue ; margi n : 5 px ; }
. re d2 { co lor : red ; background - color : ye llow ; ma rgin : 5 px ; }
together with the HTML markup
<p c lass =" red1 blue "> class =" red1 blue " , blue after red1 in style sheet </p>
<p c lass =" blue red1 "> class =" blue red1 " , blue after red1 in style sheet </p>
<p c lass =" red2 blue "> class =" red2 blue " , red2 after blue in style sheet </p>
<p c lass =" blue red2 "> class =" blue red2 " , red2 after blue in style sheet </p>
that will be rendered as
•
.red1.blue has higher specificity than both .red1 and .blue
•
margin is still determined by .blue
COMP519 Web Programming Lecture 6 Slide L6 – 19