Home > Web Front-end > CSS Tutorial > css class selector and id selector

css class selector and id selector

高洛峰
Release: 2016-11-24 15:04:15
Original
1727 people have browsed it

In CSS, the class selector is displayed with a period:

.center {text-align: center}
In the above example, all HTML elements with the center class are centered.

In the HTML code below, both h1 and p elements have the center class. This means that both will respect the rules in the ".center" selector.

This heading will be center-aligned

This paragraph will also be center-aligned.



*******************************
id selector
The id selector can specify a specific style for HTML elements marked with a specific id . The id selector is defined with "#". For the two id selectors below, the first one can define the color of the element as red, and the second one can define the color of the element as green:
#red {color:red;} #green {color:green;}
The following HTML In the code, the p element whose id attribute is red is displayed in red, and the p element whose id attribute is green is displayed in green.

This paragraph is in red.

This paragraph is green.


Note: The id attribute can only appear once in each HTML document. To find out why, see XHTML: Website Refactoring.


Related labels:
css
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template