css selector is undoubtedly very important in learning css, so, What is css selector? What types of css selectors are there? This is what we must master. This article will introduce to you the basic definition of css selectors and what types of css selectors there are.
Without further ado, let’s go directly to the topic~~
What is the css selector?
In Baidu Encyclopedia, we can see that the basic definition of css selector is: each css style definition consists of two parts, the form is as follows: [code] Selector {style} [/code ] The part before {} is the "selector". After saying such a long paragraph, in short, it is to use css to achieve one-to-one, one-to-many or many-to-one control of elements in the html page. This requires the use of CSS selectors, html pages The elements in are controlled through CSS selectors. (Recommended video tutorial: CSS tutorial)
Next we will look at a picture, which is a specific analysis of the above definition.
As shown in the figure, we can know:
The part before {} is the "selector", and the "selector" specifies the elements in {} The object of "style", that is, which elements in the web page are affected by "style"
The selector is usually the HTML element you need to change the style, such as:
,
,< ;h1>WaitingEach format declaration statement consists of a pair of "attribute name: attribute value". The attribute name and attribute value are separated by colons. Each declaration statement is preceded by a semicolon in English "; "Finish.
After introducing what a css selector is, let’s take a look at what types of css selectors there are?
What are the types of css selectors?
There are many types of css selectors. Let’s take a look at the types of css selectors
1. Tag selectors (such as: body, div,p,ul,li).
2. Class selector (such as: class="head", class="head_logo").
3. ID selector (such as: id="name", id="name_txt").
4. Global selector (such as: *).
5. Combination selectors (such as: .head .head_logo, please note that the two selectors are separated by the space bar).
6. Inherit the selector (such as: div p, note that the two selectors are separated by the space bar).
7. Pseudo-class selector (for example: link style, pseudo-class of a element, 4 different states: link, visited, active, hover.).
8. Attribute selectors for string matching (^ $ * three types, corresponding to start, end, and inclusion respectively).
The most commonly used CSS selectors among the above eight CSS selectors are label selectors, .class selectors, ID selectors, attribute selectors, and pseudo-class selectors.
Below we will give an example of each of these five css selectors: (For other selector examples, please refer to css manual)
(1) Tag selector:
<html> <head> <meta charset="UTF-8"> <title>标签选择器</title> <style type="text/css"> span{color: green;font-size: 20px} </style> </head> <body> <span>hello</span><br/> <span>world</span> </body> </html>
The effect is as follows:
## (2) Class selector:
<html> <head> <meta charset="UTF-8"> <title>class选择器</title> <style type="text/css"> .style1{background-color: green} .style2{background-color: yellow} </style> </head> <body> <div class = "style1">div1</div> <div class = "style1">div2</div> <div class = "style2">div3</div> </body> </html>The effect is as follows:
(3) ID selector:
<html> <head> <meta charset="UTF-8"> <title>ID选择器</title> <style type="text/css"> #div1{background-color: yellow} #div2{background-color: green } </style> </head> <body> <div id = "div1">div1</div> <div id = "div1">div1</div> <div id = "div2">div2</div> </body> </html>The effect is as follows:
(4) Attribute selector:
<html> <head> <meta charset="UTF-8"> <title>属性选择器</title> <style type="text/css"> input[type = 'text'] {background-color: gray} input[type = 'password'] {background-color: pink} </style> </head> <body> <form> name:<input type = "text"><br/> pass:<input type = "password"> </form> </body> </html>The effect is as follows:
(5) Pseudo-class selector:
<html> <head> <meta charset="UTF-8"> <title>伪类选择器</title> <style type="text/css"> a:link{color:yellow ;font-size: 50px} a:hover{color:green;font-size: 50px} a:active{color:blue;font-size: 50px} a:visited{color:red;font-size: 50px} </style> </head> <body> <a href = "http://www.php.cn">点击</a> </body> </html>Effect description:
When the mouse is placed on the label, the label It is green
The label is blue when the label is clicked
The label is red after clicking
css class selector and id selector
The above is the detailed content of What is a css selector? What types of css selectors are there?. For more information, please follow other related articles on the PHP Chinese website!

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

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo

CSSCountersareusedtomanageautomaticnumberinginwebdesigns.1)Theycanbeusedfortablesofcontents,listitems,andcustomnumbering.2)Advancedusesincludenestednumberingsystems.3)Challengesincludebrowsercompatibilityandperformanceissues.4)Creativeusesinvolvecust

Using scroll shadows, especially for mobile devices, is a subtle bit of UX that Chris has covered before. Geoff covered a newer approach that uses the animation-timeline property. Here’s yet another way.


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 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

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.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
