1 / 8

Specificity

CS 081 – HTML and Web Programming – Lecture 4. Specificity. Conflicting Styles 1. div { color: red; } div { color: blue; } Is the div red or blue?. Specificity Rule 1. If any rules that have the same specificity. The last rule will apply. Conflicting Styles 2.

cosmo
Download Presentation

Specificity

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 081 – HTML and Web Programming – Lecture 4 Specificity

  2. Conflicting Styles 1 div { color: red; } div{ color: blue; } Is the div red or blue?

  3. Specificity Rule 1 • If any rules that have the same specificity. The last rule will apply.

  4. Conflicting Styles 2 div p{ color: red; } p { color: blue; } Assume a p with a parent div. Is the p red or blue?

  5. Specificity Rule 2 The p is red because its selector is more specific.

  6. Calculating Specificity • Tag selectors have value 1 • Class selectors have value 10 • Id selectors have value 100 • Inline Style selectors have value 1000 • Depreciated (Avoid) • To calculate specificity you add up the values: • Combo, Descendant, Child, and Sibling Selectors have no value.

  7. Examples p > p p{color:blue;} Specificity 3 p pp {color:red;} Specificity 3 p+p{color:green;}Specificity 2 #red.green Specificity 110 .green #redSpecificity 110 #red p > p .green p.red Specificity 123 body#pool Specificity 101 #body#pool Specificity 200

  8. Specificity • Typically you would use the least number of selectors needed to select a particular element. • If later on that rule gets accidentally overridden, then you need to increase specificity.

More Related