CSS generic and grouping selector (10), css generic grouping Selector

Source: Internet
Author: User

CSS generic and grouping selector (10), css generic grouping Selector
I. general Selector

A general selector may be the most powerful but least used of all selectors. A general selector acts like a wildcard that matches all available elements. A general selector is represented by an asterisk. A general selector is used to apply styles to all elements on an object page.

For example, you can use the following rules to delete the default blank boundary on the first element.

*{margin:0;padding:0;}

 

Ii. Group Selector

The Group selector is not a type of selector, but a method of using the selector. When multiple objects define the same style, they can be grouped into a group to simplify the code.

/* Define the titles and paragraphs of all levels as 22px */h1, h2, h3, h4, h5, h6, p {line-height: 22px ;}

Group selector. You can use commas to separate different objects in the same group. The Group selector and class selector are similar in nature and can define the same style for different elements or objects.

Change the following style

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

Group selector usage

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

The Group selector adheres to the following two principles:

  • Convenience principle. You cannot group objects for group purposes. For example, if you extract the same declarations from each element or object into a group, you can only bother yourself. Defining a class is more convenient.
  • Proximity principle. If several elements are adjacent and in the same module, you can extract the same declaration and group it. The reason is easy to group, easy to maintain, and easy to understand.

 

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.