CSS Universal and Group selector (10)

Source: Internet
Author: User

I. Universal Selector

The universal selector is probably the most powerful of all selectors, but with minimal use. The universal selector acts like a wildcard, which matches all available elements. The universal selector is represented by an asterisk. Generic selectors are typically used to apply styles to all elements on an object page

For example, you can use the following rule to remove the default white space boundary on the first element

* {margin:0; padding:0;}

Second, group selector

The group selector is not a selector type, but rather a selector usage method. When multiple objects define the same style, they can be grouped into groups, simplifying the code.

/* define title and paragraph line height of 22px for all levels */ h1,h2,h3,h4,h5,h6,p {    line-height:22px;}

Grouping selectors, you can use commas to separate different objects within the same group. The group selector is somewhat similar in nature to the class selector, and you can define the same style for different elements or objects.

Change the following styles

. Class1 {    font-size:13px;     color:red;     text-decoration:underline;    } . Class2 {    font-size:13px;     color:blue;     text-decoration:underline;    }

The group selector uses

. Class1 {    color:red;    } . Class2 {    color:blue;    }    /* Common Style */ . Class1,class2 {    font-size:13px;     text-decoration:underline;    }

Group selector adhere to the following two principles

    • Convenience principle. Can not be grouped for grouping, such as each element, the object has the same declaration are extracted into a group, can only bring trouble to themselves. It is more convenient to define a class at this time
    • Nearest principle. If several elements are adjacent and within the same module, consider extracting the same declaration for grouping. Reasons for easy grouping, ease of maintenance, and easier understanding

CSS Universal and Group selector (10)

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.