Three common style selectors in html css

Three common style selectors in html css

1: Tag selector

The tag selector is used for all tags. Here we take p as an example, that is, all the tags with p will have this style.


Copy code
The code is as follows:

<html>
<head>
<styletype="text/css">
p{font:"宋体"; color:#FF0000}
</style>
</head>
<body>
<pid="p1">I am now showing the tag selector</p>
<pid="p2">I also use the tag selector</p>
<h1>I am not modified by any selector</h1>
</body>
</html>

2: id selector . Note that the id selector is unique, because only id="yy" has this style, and the ID of an element in a page must be unique, so. . . You know that the id selector starts with # and is used as follows: id=""


Copy code
The code is as follows:

<html>
<head>
<styletype="text/css">
#yy{font:"宋体"; color:#FF0000}
</style>
</head>
<body>
<pid="yy">I am now showing the id selector</p>
<pid="p">I am not modified by the id selector</p>
<h1>I am not modified by any selector</h1>
</body>
</html>

3: Class selector . Class selectors start with . Just set the element's class="" to display this style. The usage is: class=""


Copy code
The code is as follows:

<html>
<head>
<styletype="text/css">
.yy{font:"宋体"; color:#FF0000}
</style>
</head>
<body>
<pclass="yy">I am now showing the class selector</p>
<pclass="yy">I am not modified by the class selector</p>
<h1>I am not modified by any selector</h1>
</body>
</html>

<<:  Centos8.3, docker deployment springboot project actual case analysis

>>:  CSS perfectly solves the problem of front-end image deformation

Recommend

A simple way to put HTML footer at the bottom of the page

Requirement: Sometimes, when the page content is ...

Detailed explanation of error handling examples in MySQL stored procedures

This article uses an example to describe the erro...

Native js to achieve star twinkling effect

This article example shares the specific code of ...

33 ice and snow fonts recommended for download (personal and commercial)

01 Winter Flakes (Individual only) 02 Snowtop Cap...

Angular Dependency Injection Explained

Table of contents Overview 1. Dependency Injectio...

Detailed explanation of the difference between uniapp and vue

Table of contents 1. Simple page example 2.uni-ap...

Methods of adaptive web design (good access experience on mobile phones)

1. Add the viewport tag to the HTML header. At th...

Vue implements the shake function (compatible with ios13.3 and above)

Recently, I made a function similar to shake, usi...

js array entries() Get iteration method

Table of contents 1. Detailed syntax of entires()...

How to connect JDBC to MySQL 5.7

1. First prepare the MySQL and Eclipse environmen...

Solve nginx "504 Gateway Time-out" error

Students who make websites often find that some n...

Four categories of CSS selectors: basic, combination, attribute, pseudo-class

What is a selector? The role of the selector is t...

javascript implements web version of pinball game

The web pinball game implemented using javeScript...