Common css attributes: id and class selector, css Selector

Source: Internet
Author: User

Common css attributes: id and class selector, css Selector

This is the second time I wrote a blog and recorded what I learned. I hope you can join me!

Speaking of selector, we are familiar with it. It is estimated that id selector and class selector are the most used. As for other selectors, I will not talk about them here today.

Class selector: gets a loud name from the html element and marks it with class to use the class selector, for example, <p class = "p1"> This is section 1 </p>. Here I set the p element class
Is "p1", and then you can directly use the css style,

Example:

<Style type = "text/css">
P. p1 {color: red ;}
</Style>

</Head>
<Body>
<P class = "p1">
This paragraph will also be center-aligned.
</P>
</Body>
</Html>


After running the previous Code, set the text color of the p element with the class name p1 to Red. Isn't it easy? It indicates that the non-p element class name p1 has no effect, all
If the element whose class name is p1 has an effect, you need to remove the previous structure element name. The current projects are all agile development, so you have to be careful with the class name. At the beginning, people often complain.
A class name conflict means that the style conflicts with each other. Therefore, we set a convention in the project to name the class name using the page function to avoid class name conflicts.

In addition, you need to mention multiple types of names:


<P class = "p1 center">
This paragraph will also be center-aligned.
</P>


A class value can have a list of words separated by spaces. Then you can write the styles one by one. It is estimated that some people will ask: if there are
What will happen to the same css style! Here we will read the following questions about css cascade! Today's article is here. The first write may be incoherent.
I want to improve it later!

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.