Previous | Home | Next |
There are three main types of selectors:
- type selectors: Type selectors target elements by their element type.
- class selectors: Class selectors allow us to apply the same styles to different elements at once by using the same
class attribute value across multiple elements.
The class selector selects elements with a specific class attribute.
To select elements with a specific class, write a period character, followed by the name of the class:
CSS
.hellodelhi { color: green }
HTML
<div class="hellodelhi">color: green</div> <p class="hellodelhi">color: green</p>
ID selectors: ID selectors are even more precise than class selectors, as they target only one unique element at a time. The id selector uses the id attribute of an HTML element to select a specific element. An id should be unique within a page, so the id selector is used if you want to select a single, unique element.
To select an element with a specific id, write a hash character, followed by the id="hellodelhi"of the element.
#hellodelhi { color: red;}
h1 { color: red }
Previous | Home | Next |