In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to define styles according to the contextual relationship of elements in CSS. I hope you will get something after reading this article. Let's discuss it together.
CSS id selector
The id selector can specify a specific style for HTML elements marked with a specific id.
The id selector is defined by "#".
The id attribute can only appear once in each HTML document.
Example
# red {color:red;} # green {color:green;}
Note: of the two id selectors above, the first defines the element with a red color and the second defines the element with a green color.
This paragraph is red.
This paragraph is green.
Note: the p element whose id attribute is red is shown in red, while the p element whose id attribute is green is shown in green.
Tip: the id attribute can only appear once in each HTML document and is the only identifier (such as: JS gets page elements).
Id selector and derived selector
In modern layouts, id selectors are often used to build derived selectors.
Elements marked as sidebar can only appear once in the document, but this id selector can be used multiple times as a derived selector.
Example
# sidebar p {font-style: italic; text-align: right; margin-top: 0.5em;} # sidebar h3 {font-size: 1em; font-weight: normal; font-style: italic; margin: 0; line-height: 1.5; text-align: right;}
Hint: both the p element and the h3 element within the element where id is sidebar have been specially treated.
Separate selector
The id selector works independently, even if it is not used to create a derived selector:
# sidebar {border: 1px dotted # 000; padding: 10px;}
Tip: elements whose id is sidebar will have the black dotted border of 1px and the inner margin of 10px (padding).
Note: older Windows/IE browsers may ignore this rule unless you specifically define the element to which this selector belongs:
Div#sidebar {border: 1px dotted # 000; padding: 10px;} after reading this article, I believe you have a certain understanding of "how to define styles according to the contextual relationship of elements in CSS". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.