id and class selector

Set CSS styles in front-end development HTML elements, and you can set "id" and "class" selectors in the elements.

 

1.id selector

The id selector can specify a specific style for HTML elements marked with a specific id. HTML elements use id attributes to set id selectors, and id selectors are defined by "#" in CSS.

Example 1

#copyright {text-align: center;color: #ffffff;font-size: 12px; width: 250px;}

Example 2

#abc { text-align:center; color:red; } 

2.class selector 

The class selector is used to describe the style of a group of elements. The class selector is different from the id selector. Class can be used in multiple elements.

The class selector is represented by the class attribute in HTML, and in CSS, the class selector is displayed with a dot "."

Example 1

.textcenter {text-align:center;}

Example 2

You can specify specific HTML elements to use class. Let all p elements use class="center" to center the text of the element

p.textcenter {text-align:center;}

 

Guess you like

Origin blog.csdn.net/zjpjay/article/details/108592706