Current location - Quotes Website - Signature design - What is a css selector?
What is a css selector?

The main function of CSS is to set styles for DOM elements in web pages, and selectors are used to match DOM elements.

There are three types of selectors in CSS, namely label selector (based on element tag name), class selector (based on element class attribute), id selector (based on element id attribute), and three Selectors can be used in combination with each other

For example:

body{background-color:red}

//The body here is the label selector, {} The middle is to set the background color of the matching element, that is, set the body background color to red

#main{width:600px}

//#main here is the id selector, matching The element with the id of main in the web page

.logo{width:300px}

//The .logo here is the type selector, matching the elements with the class of logo in the web page

p>

div.logo{width:300px}

//The div.logo here combines the tag selector and the class selector to match the div element with the class logo in the web page