WDD 130: Web Fundamentals

W03 Learning Activities: CSS Selectors – Type, Universal, Class, ID

Overview

CSS selectors allow us to target specific elements on the page on which to apply a collection of CSS declarations. It is the subject line of a CSS rule.

Prepare

Activity Instructions

  1. In VS Code, open the class-and-id.html file located in the week03 folder.
  2. Also open the class-and-id.css file located in the week03 styles subfolder.
  3. Display the page in your browser using Live/Five Server and review the layout and styles applied to the div elements.
  4. In VS Code, remove the highlight class from the second <div> leaving only one class for that paragraph named box. What happens? You may need to open up the CSS file
    Check Your Understanding

    <div class="box">
    That second div is no longer styled with the "highlight" class and therefore loses those specific declarations.

  5. In the HTML, attempt to add another div element with the id attribute of "note" like this
    <div id="note">
      <p>Testing the note ID.</p>
    </div>
    What happens in VS Code?
    Check Your Understanding

    In VS Code, the editor warns you of a problem by highlighting the duplicate id attribute with a squiggly line.

    Duplicate ID Warning

    Note that the browser will actually apply the CSS style, but this application is an HTML validation error that the browser tries to ignore for you.

Optional Resources