Home > Web Front-end > CSS Tutorial > What is the way to set css style in html element

What is the way to set css style in html element

王林
Release: 2020-08-10 16:59:34
Original
2728 people have browsed it

What is the way to set css style in html element

If we want to set CSS styles in HTML elements, then we need to set the "id" and "class" selectors in the element.

(Recommended tutorial: CSS tutorial)

Let’s talk about the id selector and class selector respectively.

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 "#".

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

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

Example:

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

Note: The first character of the class name cannot be a number! It won't work in Mozilla or Firefox.

The above is the detailed content of What is the way to set css style in html element. 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