CSS * Selector

CSS * Selector

CSS * Selector


The * (asterisk) selector selects all elements in a document.

The * selector can also select all elements inside another element.

Version 

CSS2 Universal Selector

Syntax

* {
  css declarations;
}

Example of the * selector:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      * {
        background-color: #8ebf42;
      }
    </style>
  </head>
  <body>
    <h2>* selector example</h2>
    <div class="example">
      <p id="example1">Lorem ipsum is simply dummy text...</p>
      <p id="example2">Lorem ipsum is simply dummy text...</p>
    </div>
    <p>Lorem ipsum is simply dummy text...</p>
  </body>
</html>

Example of the * selector for a <div>  element:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      div * {
        background-color: #8ebf42;
      }
    </style>
  </head>
  <body>
    <h2>* selector example</h2>
    <div class="example">
      <p id="example1">Lorem ipsum is simply dummy text...</p>
      <span id="example2">Lorem ipsum is simply dummy text...</span>
    </div>
    <p>Lorem ipsum is simply dummy text...</p>
  </body>
</html>

Practice Your Knowledge

The * (asterisk) selector selects

Reactions

Post a Comment

0 Comments

close