directory

 

Packet selector

Nested selectors


Packet selector

There are many elements in the style sheet that have the same style.

    h1 {
        color:green;
    }
    h2 {
        color:green;
    }
    p {
        color:green;
    }
Copy the code

To minimize code, you can use group selectors.

Each selector is separated by a comma.

In the following example, we use a grouping selector for the above code:

    h1.h2.p {
        color:green;
    }
Copy the code

Nested selectors

It may apply to styles of selectors inside selectors.

The following example sets three styles:

  • P {}: Specifies a style for all p elements.
  • .marked{}: Specify a style for all class= “marked” elements.
  • .marked p{}: for all class= “marked”