DEV Community

ChuangWANG
ChuangWANG

Posted on

CSS

English website ref:
https://www.w3schools.com/cssref/css_selectors.asp
Chinese website ref:
https://www.runoob.com/cssref/css-selectors.html
Select all element and set background color:

* { 
  background-color:yellow;
}
Enter fullscreen mode Exit fullscreen mode

Select all element inclosed by div:

div * {
  background-color:yellow;
}
Enter fullscreen mode Exit fullscreen mode

Class selector:

.intro {
  // select all elements their has class="intro" marker
}
Enter fullscreen mode Exit fullscreen mode

Id selector:

#firstname {
  // select all elements their has id="firstname" marker
}
Enter fullscreen mode Exit fullscreen mode

Element selector:

div {
  // all div tag will be selected
}
Enter fullscreen mode Exit fullscreen mode

Element,Element selector:

div,span {
  // select all div and span tag
}
Enter fullscreen mode Exit fullscreen mode

Element Element selector:

div span {
  // select all span tags that inclosed by div tag
}
Enter fullscreen mode Exit fullscreen mode

Element>Element selector:

div>p {
  // select all p elements their father element is div
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)