Home  >  Article  >  Web Front-end  >  Introduction to id selector and class selector in css

Introduction to id selector and class selector in css

王林
王林Original
2020-05-23 16:25:262761browse

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;
}

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;}

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;}

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!

Statement:
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
Previous article:CSS size as a percentageNext article:CSS size as a percentage