Css id selector and CLASS selector

Source: Internet
Author: User

Css id selector and CLASS selector
In CSS, a selector is a pattern used to select elements that require adding styles.
The attribute selector can select an element based on its attributes and attribute values.

Three basic selector types: Tag name selector, class selector, and ID Selector

The syntax is as follows:

1. Tag name selector, such:

 

html {color:black;}h1 {color:blue;}h2 {color:silver;}
That is, the HTML Tag is directly used as the selector.

 

2. class selector

The class selector allows you to specify styles in a way independent of document elements.
This selector can be used independently or in combination with other elements.
Tip: these selectors can be used only after the document is properly marked. Therefore, using these two selectors usually requires some ideas and plans.
To apply styles without considering specific design elements, the most common method is to use class selectors.

Demo:

 

.important {font-weight:bold;}.warning {font-style:italic;}.important.warning {background:silver;}
All the elements whose class is important are bold, while all the elements whose class is warning are italic, and all the elements whose class contains both important and warning have a silver background.

 

3. ID Selector

Summary:

What is the difference between a class selector and an ID selector?

ID has a high priority and uniqueness, specifically "individual 」.
Compared with ID, class has a moderate priority, especially for "Specific groups 」.
To use Class, you need to refer to the object-oriented abstract concepts to abstract common attributes.

ID is to first find the structure/content, and then define the style;
Class is to define a style first, and then set it to multiple structures/content.

For wildcards:

Because different browsers have different default styles for the same page elements, it is necessary to use the wildcard asterisk (*) to unify all the default styles that may affect the layout. The asterisk (*) matches all elements, saving the trouble of writing element names one by one.

However, because * matches all elements, this will affect the time for rendering the web page. Therefore, many people start to stop using the * wildcard selector. Instead, all elements that need to be set in a unified manner, put them together and set them one by one.

Test code:

 

     1. what's best in life is not the moment of success, but the dark process that seems endless and hard to find. In fact, I only care about where I am in the heart of the person I want. 1. The greatest thing in life is not the moment of success, but 3333333333. 

2. If your life is less satisfactory, you must learn your own warmth and comfort,
Give yourself more appreciation and encouragement. Life is a fairy tale,
As long as you have a good heart, the ending will be beautiful.

3. The name of the spectator will never climb the score board of the competition.

4. strong faith will win strong people and then make them stronger.

5. As long as we can dream of it, we can achieve it.

6. Each winner has a start. Only when you have the courage to start can you find the way to success.

7. Self-improvement personnel cannot help themselves. Self-improvement personnel cannot help themselves.

8. Do not make excuses for failure. Only find reasons for success. (Not the reason for failure, but the method for success)

9. Last night, I had several minutes of preparation, but today I had less trouble.

10. As long as the road is right, you are not afraid of the road.



 

 

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.