6.3 Basic

  • CSS declaration structure:

    selector {
      property1: value1;
      property2: value2;
    }

Select by tag name

  • Select one HTML element via its tag name:

    span {
      color: red;
    }
  • Select multiple HTML elements via their tag name:

    p, div {
      background-color: lightsalmon;
    }

Select by class or id

  • Example of attributes class and id: <p class="random" id="not-random">some text</p>

  • Respective CSS selectors:

    /* class 
      Style for one or many elements
    */
    .random {
      color: gold;
      background-color: black;
    }
    
    /* id 
      Style for only one specific element
    */
    #not-random {
      color: crimson;
    }