CSS Tutorials

adplus-dvertising
Selectors In CSS
Previous Home Next

There are three main types of selectors:

  1. type selectors: Type selectors target elements by their element type.
  2. h1 { color: red }
    
  3. 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>
    
  4. 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;} 
    
Previous Home Next