Cascading Style Sheets – What are the seven rules of CSS selectors?

courses

Here are seven rules of CSS selectors p, h2,. Note, p # paragraph1, a: hover, # news p and [type = "button"].

The first rule is set to HTML element p (paragraph). Paragraphs will be displayed using the font Garamond, or if a font is not available, any other font with serifs («serif»).

The second rule is set to HTML element h2 (header of the second level). Title of the second level will be displayed in red on a white background with increased size.

The third rule will be applied to any element whose class attribute is ‘note’. For example, the paragraph : <p> This paragraph will be displayed in bold red on a yellow background. </ P>

The fourth rule is applied only to the element p, which is equal to the id attribute paragraph1. This item will not have external margins (margin).

The fifth rule defines the style elements hover for hyperlinks. By default, most browsers elements of a text is underlined. This rule will remove the underline when the mouse hovers over these elements.

The sixth rule is applied to elements of p, which are inside of an element with an attribute id, equal to «news» (# news p – this is a typical case of a descendant selector , see point 5 of the list above).

The seventh rule is applied to all elements whose type attribute is button. For example , this rule will be applied to the element <input type=”button”> ( normal button ) , changing its background color to green.

If some of these properties, above all, the style specified by the user is preferred, and for the other properties (which will be defined by author of the page) will need to determine their specificity on the principles described above and apply these properties in descending order of their specificities.

The calculation principle is that, for example, (1,0,0,0) will have greater specificity, respectively – a higher priority than even (0,10,0,0), (0,1,0,0) will be greater specificity, greater priority than (0,0,10,0) and (0,0,1,0) will have a higher priority than (0,0,0,10).

 

About the Author