How to use attribute selectors and pseudo-class selectors

php中世界最好的语言
Release: 2017-11-24 10:00:43
Original
2380 people have browsed it

Today we will tell you about the usage and related connections and differences between Attribute Selector and PseudoClass Selector. Here is a small example.

Attribute selector:

[attr~="value"] Word Word Space Word Word must be valid

[attr|="value"] Value starts with or value - Word

Note:

It is difficult to use rules expressions to identify selected elements when selecting attributes, which is more efficient

Pseudo-class Selector:

: before

: after

:lang(val) val/val-word

:nth-child(n) nfrom Starting from 1, odd base and even even number

:nth-of-type(n) selector matches every element that is the Nth child element of a specific type of the parent element.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<link href="css/index.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!--
<p>aaaaaaa</p>
<p>aaaaaaa</p>
<p>aaaaaaa</p>
--->
<div>
       <p>aaa</p>
       <p>aaa</p>
       <p>aaa</p>
       <p>aaa</p>
</div>
</body>
</html>
Css部分:
@charset "utf-8";
/* CSS Document */
/*
p:before{
       content:"ccc"; 
}
 
p:lang(en){
       border:1px solid #ff0000;  
}
p:nth-child(even){
       background:#F00; 
}
*/
p:nth-of-type(3){  /* p标记的父元素 下的 第3个p元素*/
       background:#F00; 
}
Copy after login

Related Read:

How to hide content that overflows a DIV

What are the techniques for CSS layout

Font styles in CSS How to set up

The above is the detailed content of How to use attribute selectors and pseudo-class selectors. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!