What selectors are there in css?
CSS selectors include: 1. Category selector; 2. Tag selector; 3. ID selector; 4. Descendant selector; 5. Sub-selector; 6. Pseudo-class selector; 7 , Universal selector; 8. Group selector; 9. Adjacent sibling selector; 10. Attribute selector; 11. Pseudo element selector.
The operating environment of this tutorial: Windows7 system, CSS3&&HTML5 version, Dell G3 computer.
css selector introduction:
1. Category selector
The class selector selects based on the class name, preceded by "." .
Example:
.demoDiv{ color:#FF0000; }
2. Tag selector
A complete HTML page is composed of many different tags, and the tag selector determines which tags are used Corresponding CSS styles.
The declaration of the p tag style in the style.css file is as follows:
p{ font-size:12px; background:#900; color:090; }
3. ID selector
The ID selector can be an HTML element marked with a specific ID Specify a specific style. Select elements based on element ID, which is unique, which means that the same ID can only appear once in the same document page.
is preceded by a "#" sign and can be defined in the style as follows:
#demoDiv{ color:#FF0000; }
4. Descendant selector
Descendant selector is also called inclusion The selector is used to select the descendants of a specific element or element group. The selection of the parent element is placed in front and the selection of child elements is placed in the back, separated by a space in the middle.
<style> .father.child{ color:#0000CC; } </style> <p class="father"> 黑色 <label class="child">蓝色 <b>也是蓝色</b> </label> </p>
5. Child selector
Please note the difference between this selector and the descendant selector. The child selector only refers to its direct descendants, or your It can be understood as acting on the first descendant of the child element. The descendant selector acts on all child descendant elements. Descendant selectors select with spaces, while child selectors select with ">".
Let’s look at the following code:
Example Source Code
CSS:
#links a {color:red;} #links > a {color:blue;}
HTML:
<p id="links"> <a href="#">HTML中文网</a>> <span><a href="#">CSS布局实例</a></span> <span><a href="#">CSS教程</a></span> </p>
6. Pseudo-class selection The handler
Sometimes you need to use other conditions outside the document to apply the style of the element, such as mouse hover, etc. At this time we need to use pseudo classes. The following is the pseudo-class definition for the linked application.
a:link{ color:#999999; } a:visited{ color:#FFFF00; } a:hover{ color:#006600; } /* IE不支持,用Firefox浏览可以看到效果 */ input:focus{ background:# E0F1F5; }
7. Universal selector
The universal selector is represented by *. For example:
*{ font-size: 12px; }
means that the font size of all elements is 12px; at the same time, the universal selector can also be combined with descendant selectors.
8. Group selector
When several elements have the same style attributes, they can call a statement together and separate the elements with commas. For example:
p, td, li { line-height:20px; color:#c00; } #main p, #sider span { color:#000; line-height:26px; } .#main p span { color:#f60; } .text1 h1,#sider h3,.art_title h2 { font-weight:100; }
Using the group selector will greatly simplify the CSS code. Elements with multiple identical attributes can be merged into groups for selection, and the same CSS attributes can be defined, which greatly improves coding. efficiency, and also reduces the size of CSS files.
9. Adjacent sibling selector
In addition to the above child selector and descendant selector, we may also want to find one of the two brothers, such as a title h1 The element is followed by two paragraph p elements. We want to locate the first paragraph p element and apply styles to it. We can use the adjacent sibling selector.
10. Attribute selector
You can define css by judging whether a certain attribute of the html tag exists.
Attribute selector is matched based on the attributes of the element. Its attributes can be standard attributes or custom attributes
11. Pseudo-element selector
All pseudo-element selectors must be placed at the end of the selector in which the pseudo-element appears, which means that the pseudo-element selector cannot be followed by any derived selector.
Recommended learning: css video tutorial
The above is the detailed content of What selectors are there in css?. For more information, please follow other related articles on the PHP Chinese website!

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-
