1024programmer CSS What is css compound selector?

What is css compound selector?

Css compound selector is composed of two or more basic selectors combined in different ways, the purpose is to select more Accurate and finer-grained labeling of target elements. CSS composite selectors include sub-selectors, adjacent selectors, containment selectors, multi-layer selector nesting, attribute selectors, pseudo-selectors and pseudo-element selectors. The specific usage of the above is as follows:

1. The sub-selector code is as follows:


 photo
 click to enlarge
 

2. Adjacent selector

If you need to select an element immediately after another element, and both have the same parent element, you can use the adjacent sibling selector ( Adjacent sibling selector).

For example, if you want to increase the top margin of a paragraph that appears immediately after the h1 element, you can write:

h1 + p {margin-top:50px;}

This selector reads: “Selects the paragraph that appears immediately after the h1 element that has a common parent with the p element”.

3. Include the selector

The code is as follows:

#header p{font-  size:14px}
 #main p {font-size:12}

Define the font size of the paragraph in the containing box as 14 pixels
Define the font size of the paragraph in the containing box as 12 pixels.

4. Multi-layer selector nesting

The code is as follows:

#wrap #header h2 span {font  -size:24px}
 #wrap #main h2 span {font-size:14px}

5. Attribute selector

(1) Matching attribute name selector

div[class] {font-size:24px;}

Make this selector match the object definition format with class attribute set in div

(2) Matching attribute value selector

img[alt="image"][title="image"] {  border: solid 2px red}: 

Define style for image

(3) blur Match attribute value selector

6. Pseudo-selector and pseudo-element selector


The above is the detailed content of what is the CSS compound selector? For more information, please pay attention to other related articles on 1024programmer.com!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/what-is-css-compound-selector/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索