Parsing 30 of the most commonly used selectors in CSS

Source: Internet
Author: User

Article Introduction: 30 most commonly used CSS selector parsing.

You may have mastered the basic CSS selectors for ID, class, and background selectors. But this is far from all of CSS. The following is a systematic analysis of the 30 most commonly used selectors in CSS, including our most headache browser compatibility issues. Master them, you can really appreciate the great flexibility of CSS.

1.


* {
margin:0;
padding:0;
}
The star selector will work on every element on the page. Web designers often use it to set the margin and padding of all elements in a page to 0.

The * selector can also be used in a child selector.


#container * {
BORDER:1PX solid black;
}
The above code is applied to all child elements with an ID container element.

Unless necessary, I do not recommend using the Star selector on the page because his scope is too large to consume browser resources.

Compatible browsers: ie6+, Firefox, Chrome, Safari, Opera

2. #X


#container {
width:960px;
Margin:auto;
}
The well number scope has an element of the corresponding ID. ID is one of our most common CSS selectors. The advantage of ID selector is precision, high priority (priority base is 100, far higher than Class 10), as the JavaScript script hook is the best choice, the same disadvantage is also obvious high priority, reusability is poor, so before using ID selector, we'd better ask ourselves, Really to the point of not using ID selector?

Compatible browsers: ie6+, Firefox, Chrome, Safari, Opera

3.. X

. Error {
color:red;
}

This is a class (class) selector. The difference between the class selector and the ID selector is the set of elements that the class selector can use for the desired styling.

Compatible browsers: ie6+, Firefox, Chrome, Safari, Opera

4. X Y

Li a {
Text-decoration:none;
}

This is also one of our most commonly used selectors-descendant selectors. To select the element y of the x element, the point to note is that this way the selector will select all the matching child elements below it, ignore the hierarchy, so some of the situation is not appropriate to use, such as the above code to remove all of the Li under the underline, but Li also has a UL, I do not want to ul under the Li's a remove underline. When using this descendant selector, consider whether you want a style to work for all descendant elements. This descendant selector also has the effect of creating similar namespaces. For example, the scope of the above code style is obviously li.

Compatible browsers: ie6+, Firefox, Chrome, Safari, Opera



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.