There's a lot we could talk about in front-end development, but today we only have two goals, and they relate to CSS…
!important
failures!important
Examples!important
failures!important
!important failures
Specificity is misunderstood
Often, we use !important
when we don't understand how the cascade will behave.
Remember that !important
disrupts the cascade.
.header{ background: gray; } .homepage .header{ background: blue; } /* Bunch of code happens in between*/ .header { background: yellow !important; }
!important failures
Rely on the cascade
The last item in the cascade wins. You can provide the same selector, but put it at the end, and you're fine.
.header{ background: gray; } .homepage .header{ background: blue; } /* Bunch of code happens in between*/ .homepage .header { background: yellow; }
!important failures
div#someSpecificThing
)
section .article #someSpecificThing
)#someHeader{font-size:4em}
!important
Efficient Selectors
Specificity is misunderstood
Often, we use !important
when we don't understand how the cascade will behave.
Remember that !important
disrupts the cascade.
/* good */ header{ background: gray; } /*better */ .header{ background: gray; } /*mmmm... maybe? */ .homepage .header{ background: blue; } /*best*/ .homepageHeader{ background: blue }
Efficient Selectors
Specificity is misunderstood
Often, we use !important
when we don't understand how the cascade will behave.
Remember that !important
disrupts the cascade.
/* good */ header{ background: gray; } /*better */ .header{ background: gray; } /*mmmm... maybe? */ .homepage .header{ background: blue; } /*best*/ .homepageHeader{ background: blue }
<div id="someWrapper" class="wrapper"> <h3 id="someHeader" class="wrapper">Howdy there!</h3> </div>
<!--Insert sincere gratitude -->