What is the declaration and nesting of selectors? Declaration and nesting of CSS selectors

Source: Internet
Author: User
When using CSS selectors to control HTML markup, the properties of each selector can be declared more than once, and the selector itself can declare more than one at a time. And, any form of selector, is legal, tag Selector, class selector and ID selector can be collectively declared. When declaring a CSS selector, if the style of some selectors is exactly the same or partially the same, then the same style selector can be declared simultaneously using a collective declaration.

<span style= "FONT-SIZE:24PX;" >

Global Declaration

For a real site, if you want all of the markup in the page to use the same CSS style, but you don't want to collectively declare it individually, you can use the global declaration symbol * to declare it.

<span style= "FONT-SIZE:24PX;" >

You can see that the two declarations work exactly the same, but using a global declaration can make your code much less effective.

Nesting of selectors

In the CSS selector, you can declare HTML tags for special locations using nested methods.

For example, controlling the B mark in the P tag

<span style= "FONT-SIZE:24PX;" Nested declarations for ><HTML><HEAD><TITLE>CSS selectors </title><style type= "Text/css" ><!--P B{color: Maroon;text-decortion:underline;} --></style>

Nested selectors, which are very widely used, are not only nested tags themselves, but both category selectors and ID selectors can be nested.

The following code uses three layers of nesting, and in fact more layers of nesting are allowed, representing the. Top category of the <td> tag that contains the. TOP1 category of the <p> tag, which contains the <strong> tag that is declared by the style style.

<span style= "FONT-SIZE:24PX;" >td.top. Top1 strong{font-size:16px;} <TD class= "Top" ><p class= "Top1" > Other content <strong>css controlled parts </strong> other content </p></td> </span>

The

selectors are nested, and in CSS you can significantly reduce the declaration of class and ID, so when you build HTML for a page, you usually define class or ID only for the outer tag. The inner tag can be represented by nesting by using nested methods, so that no new class or ID needs to be defined, and a separate declaration is made only if the child tag cannot take advantage of the rule.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.