This article brings you what are the css selectors? A summary of the use of CSS selectors has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Selector (device) uses basic syntax
Selector { Attribute 1: Attribute value 1;
Attribute 2: Attribute value 2;
Attribute 3: Attribute value 3;
…..: …….;
}
2. Tag selector (directly use HTML tags as selectors)
second.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>标记选择器</title> <link href="second.css" type="text/css" rel="stylesheet"> </head> <body> <p> 标记选择器(直接使用html标签做选择器)</p> </body> </html>
second.css
p{ font-size:34px; text-align:left; text-transform:uppercase; font-family:黑体,宋体; text-indent:3em; text-decoration:line-through; font-weight:bolder; letter-spacing:0.5em; line-height:3px; margin:34px; padding:23px; }
3. Class selector (for each The label sets a class name. CSS can set the style of the label through the class name. Different labels can have the same class name, and they can share the same style.) - In CSS, label name.class name or .class name is used to express
second.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>类选择器</title> <link href="second.css" type="text/css" rel="stylesheet"> </head> <body> <p class="text"> 类选择器(为每一个标签设置一个类名,CSS可通过类名为标签设置样式,不同标签类名可以相同, 相同可以共用同一个样式)---CSS中用标签名.类名或者.类名表示 </p> </body> </html>
second.css
.text{ font-variant:small-caps;/*小型大写字母*/ font-family:宋体,黑体; font-style:italic; text-transform:lowercase; font-size:35px; text-indent:3em; text-decoration:overline; font-weight:bold; letter-spacing: 1px; line-height:3em; font-variant:small-caps; text-align:right; }
4.ID selector (set a unique ID for each HTML tag, CSS can set the style for the tag through the id)
——#id value { } is used in CSS to represent
second.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>ID选择器</title> <link href="second.css" type="text/css" rel="stylesheet"> </head> <body> <p class="text" id="textp1"> ID选择器(为每一个HTML标签设置一个唯一的ID,CSS可以通过id来为标签设置样式) ----CSS中用#id值{ }来表示 </p> </body> </html>
second.css
.text{ font-variant:small-caps;/*小型大写字母*/ font-family:宋体,黑体; font-style:italic; text-transform:lowercase; font-size:35px; text-indent:3em; text-decoration:overline; } #textp1{ font-weight:bold; letter-spacing: 1px; line-height:3em; font-variant:small-caps; text-align:right; }
5. Contains selectors (descendant selectors: can span generation, cross tags): Contain another tag in one tag
second.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>包含选择器</title> <link href="second.css" type="text/css" rel="stylesheet"> </head> <body> <p class="text" id="textp1"> <a href="#" class="link">ID选择器</a> (为每一个html标签设置一个唯一的ID,CSS可以通过id来为标签设置样式) ----CSS中用#id值{ }来表示 </p> </body> </html>
second.css
p a{ text-decoration:none; font-size:25px; background-color:pink; } .text{ font-size:21px; font-style:normal; text-transform:lowercase; text-indent:3em; font-weight:bold; letter-spacing:0.7em; line-height:27px; }
6. Sub-selector (not supported by IE browser): No other tags can be included in the middle; in CSS, tag 1 > tag 2 (sub-tag) is used to represent
second.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>子选择器</title> <link href="second.css" type="text/css" rel="stylesheet"> </head> <body> <p class="text" id="textp1"> <a href="#" class="link">子选择器</a> (IE浏览器不支持):中间不能包含其他标签;CSS中 标签1 >标签2(子标签) 表示 </p> </body> </html>
second.css
p>a{ text-decoration:none; font-family:黑体,宋体; } p{ font-size: 23px; }
7. Adjacent Selector: (CSS style is applied to the last tag) Commonly used to set column attributes of the table – CSS uses tag 1….Tag n represents
second.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>相邻选择器</title> <link href="second.css" type="text/css" rel="stylesheet"> </head> <body> <p class="text" > 子选择器: (IE浏览器不支持):中间不能包含其他标签;CSS中 标签1 >标签2(子标签) 表示 </p> <p class="text1"> 相邻选择器(CSS样式作用在最后一个标签)常用设置表格的列属性--CSS用标签1+....标签n表示 </p> </body> </html>
second.css
.text+.text1{ color:pink; background-color:gray; font-size:34px; }
8. Union selector: Set styles for multiple tags together, separated by commas
second.css
<!doctype html> <html> <head> <meta charset="utf-8"> <title>并集选择器</title> <link href="second.css" type="text/css" rel="stylesheet"> </head> <body> <p class="text" > 子选择器: (IE浏览器不支持):中间不能包含其他标签;CSS中 标签1 >标签2(子标签) 表示 </p> <p class="text1"> 并集选择器:多个标签一起设置样式,用逗号隔开 </p> </body> </html>
second.css
.text,.text1{ color:pink; background-color:gray; font-size:34px;}
9. Pseudo class (a certain state of an element, often used to describe the state of a hyperlink: link (unvisited state); visited (visited state); hover (mouse passing state); active (clicking state) CSS tags Name: Status representation
second.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>伪类</title> <link href="second.css" type="text/css" rel="stylesheet"> </head> <body> <a href="" class="a1">伪类</a> </body> </html>
second.css
a:link { color:blue; font-size:53px; text-decoration: none; } a:visited { color:red; font-size:193px; } a:hover { color:green; font-size:73px; } a:active { color:gray; font-size:183px; }
10. Pseudo element (state of an element in an object) tag name in CSS : Pseudo-class representation
Commonly used ones are (first-letter [acts on the first letter of text], first-line [acts on the first line of text])
second.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title>伪类</title> <link href="second.css" type="text/css" rel="stylesheet"> </head> <body> <p>伪元素(某个对象中某个元素的状态)CSS中用标签名: 伪元素常用的有(first-letter[作用于文字首字],first-line[作用于文字首行]) <br>伪元素(某个对象中某个元素的状态)CSS中用标签名: 伪元素常用的有(first-letter[作用于文字首字],first-line[作用于文字首行]) </p> </body> </html>
second.css
p:first-letter{ font-size:200%; } p:first-line{ color:red; }
11 Style priority: Inline selector>ID selector>Class selector (pseudo-class, attribute)>Mark selector
You can use !important; to increase the priority
Related recommendations:
css class selector and id selector
##CSS descendant selector and multi-class selector
css tag selector, id selector, class selector instance
The above is the detailed content of What are the css selectors? Summary of css selector usage. For more information, please follow other related articles on the PHP Chinese website!

@keyframesandCSSTransitionsdifferincomplexity:@keyframesallowsfordetailedanimationsequences,whileCSSTransitionshandlesimplestatechanges.UseCSSTransitionsforhovereffectslikebuttoncolorchanges,and@keyframesforintricateanimationslikerotatingspinners.

I know, I know: there are a ton of content management system options available, and while I've tested several, none have really been the one, y'know? Weird pricing models, difficult customization, some even end up becoming a whole &

Linking CSS files to HTML can be achieved by using elements in part of HTML. 1) Use tags to link local CSS files. 2) Multiple CSS files can be implemented by adding multiple tags. 3) External CSS files use absolute URL links, such as. 4) Ensure the correct use of file paths and CSS file loading order, and optimize performance can use CSS preprocessor to merge files.

Choosing Flexbox or Grid depends on the layout requirements: 1) Flexbox is suitable for one-dimensional layouts, such as navigation bar; 2) Grid is suitable for two-dimensional layouts, such as magazine layouts. The two can be used in the project to improve the layout effect.

The best way to include CSS files is to use tags to introduce external CSS files in the HTML part. 1. Use tags to introduce external CSS files, such as. 2. For small adjustments, inline CSS can be used, but should be used with caution. 3. Large projects can use CSS preprocessors such as Sass or Less to import other CSS files through @import. 4. For performance, CSS files should be merged and CDN should be used, and compressed using tools such as CSSNano.

Yes,youshouldlearnbothFlexboxandGrid.1)Flexboxisidealforone-dimensional,flexiblelayoutslikenavigationmenus.2)Gridexcelsintwo-dimensional,complexdesignssuchasmagazinelayouts.3)Combiningbothenhanceslayoutflexibilityandresponsiveness,allowingforstructur

What does it look like to refactor your own code? John Rhea picks apart an old CSS animation he wrote and walks through the thought process of optimizing it.

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor
