13.07.2015 Views

Beginning CSS: Cascading Style Sheets for Web Design, 2nd ...

Beginning CSS: Cascading Style Sheets for Web Design, 2nd ...

Beginning CSS: Cascading Style Sheets for Web Design, 2nd ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

❑Count the number of attributes, pseudo-classes, and class names in a selector; the sum isvariable c.❑ Count the number of element names in the selector; this is variable d.❑Ignore pseudo-elements.Chapter 4: The Cascade and InheritanceConcatenate each number together to get the specificity of the selector. Concatenate is a programmingterm that means glue together. In this case if I concatenate a, b, c, and d I get abcd, instead of the sum of a,b, c, and d, which I might refer to as e. Following are some examples.Selector Selector Type Specificity* Universal Selector 0000(a = 0, b = 0, c = 0, d = 0)li Element Name 0001(a = 0, b = 0, c = 0, d = 1)ul li Element Name 0002(a = 0, b = 0, c = 0, d = 2)div h1 + p Element Name 0003(a = 0, b = 0, c = 0, d = 3)input[type=’text’] Element Name + Attribute 0011(a = 0, b = 0, c = 1, d = 1).someclass Class Name 0010(a = 0, b = 0, c = 1, d = 0)div.someclass Element Name + 0011Class Name (a = 0, b = 0, c = 1, d = 1)div.someclass.someother Element Name + 0021Class Name + Class Name (a = 0, b = 0, c = 2, d = 1)#someid ID Name 0100(a = 0, b = 1, c = 0, d = 0)div#someid Element Name + ID Name 0101(a = 0, b = 1, c = 0, d = 1)style (attribute) style (attribute) 1000(a = 1, b = 0, c = 0, d = 0)I have included the leading zeros in the specificity chart to clarify how concatenation works, but theseare actually dropped. To determine the order of precedence, simply determine the highest number. Theselector with the highest number wins. Consider the example in Figure 4-3a.113

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!