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!