0 added
0 removed
Original
2026-01-01
Modified
2026-03-09
1
<p>The selector can be found at the beginning of the CSS rule before the curly braces, and it determines which HTML elements are formatted using the properties and values from the rule. Remember the following example:</p>
1
<p>The selector can be found at the beginning of the CSS rule before the curly braces, and it determines which HTML elements are formatted using the properties and values from the rule. Remember the following example:</p>
2
.feature-kitten { padding-top: 60px; /* Top margin */ background-image: url("img/bottle.svg"); /* Background image */ }<p>The .feature-kitten string is a selector. It tells the browser to apply the property list (margin and background) to all elements whose class attribute is set to the value feature-kitten.</p>
2
.feature-kitten { padding-top: 60px; /* Top margin */ background-image: url("img/bottle.svg"); /* Background image */ }<p>The .feature-kitten string is a selector. It tells the browser to apply the property list (margin and background) to all elements whose class attribute is set to the value feature-kitten.</p>
3
<p>The simplest (and most popular) selectors are the tag and class selectors. The tag selectors contain a tag name with no < and > characters and are applied to all matching tags. The class selectors start with a period, which is followed by the class name, and they are applied to all tags with the matching class attribute. For example:</p>
3
<p>The simplest (and most popular) selectors are the tag and class selectors. The tag selectors contain a tag name with no < and > characters and are applied to all matching tags. The class selectors start with a period, which is followed by the class name, and they are applied to all tags with the matching class attribute. For example:</p>
4
/* Selects all level 1 headings */ h1 { color: red; } /* Selects only the elements with the info class */ .info { color: blue; }<p>If the CSS rules differ<em>only</em>by their selectors, but they share the same properties and values, then they can be grouped together and separated by commas. For example:</p>
4
/* Selects all level 1 headings */ h1 { color: red; } /* Selects only the elements with the info class */ .info { color: blue; }<p>If the CSS rules differ<em>only</em>by their selectors, but they share the same properties and values, then they can be grouped together and separated by commas. For example:</p>
5
h1, .danger { color: red; } /* Is the very same thing as */ h1 { color: red; } .danger { color: red; }<p>And now try using several different types of selectors. Substitute the selector in the CSS rule and see what changes.</p>
5
h1, .danger { color: red; } /* Is the very same thing as */ h1 { color: red; } .danger { color: red; }<p>And now try using several different types of selectors. Substitute the selector in the CSS rule and see what changes.</p>