Introduction to id selector and class selector in css

王林
Release: 2020-05-30 16:11:59
Original
2848 people have browsed it

Introduction to id selector and class selector in css

id selector

The id selector can specify a specific style for HTML elements marked with a specific id.

The HTML element uses the id attribute to set the id selector, and the id selector in CSS is defined with "#".

For example:

#para1
{
    text-align:center;
    color:red;
}
Copy after login

Note: Do not start the ID attribute with a number. IDs starting with numbers will not work in Mozilla/Firefox browsers.

class selector

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 used in elements.

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

For example:

In the following example, all HTML elements with the center class are centered.

.center {text-align:center;}
Copy after login

You can also specify specific HTML elements using classes.

For example:

In the following example, all p elements use class="center" to center the text of the element.

p.center {text-align:center;}
Copy after login

Recommended tutorial: CSS basic tutorial

The above is the detailed content of Introduction to id selector and class selector in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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