Is there a difference between the two? The beginning refers to the first line of the css file
. Indicates class # Represents Id
For example:
1. Duplication of IDs is not allowed in web standards. For example, div id="a" is not allowed to be repeated twice; class defines a class and can theoretically be repeated infinitely. to reference as many times as necessary.
2. Attribute priority issue: ID has a higher priority than class. We have an example in the code below.
3. It is convenient to reference JS and other client scripts. If you want to perform script operations on an object in the page, you can define an ID for it. Otherwise, you can only find it by traversing the page elements and specifying specific attributes. , which is a relative waste of time and resources, and is far less simple and fast than an ID.
#id has higher priority, and the unique
.class can be used for multiple
These are style selectors
1. # is the ID selection . is a category selector
3. Tag selector For example, element p tag style, all content related to p in HTML will use the style you defined
4. Descendant selector For example, ul and li .ul li{} Then the styles of all li under ul will have the effect you defined
These are more commonly used. If you want to see the details, see Enter "css selector" in Baidu and the introduction is very detailed
1. # is the ID selector. This is less used in defining styles
2. . is a category selector
3. Tag selector For example, element p tag style, all content related to p in HTML uses the style you define
4. Descendant selectors such as ul and li. ul li{} Then all the styles of li under ul will have the effect you defined
These are more commonly used. If you want to see the details, see the introduction in Baidu "css selector" Detailed
css selector, after that there is priority!
2. Attribute priority issue: ID has a higher priority than class. We have an example in the code below.
3. It is convenient to reference JS and other client scripts. If you want to perform script operations on an object in the page, you can define an ID for it. Otherwise, you can only find it by traversing the page elements and specifying specific attributes. , this is relatively wasteful...
1
Starting with # is the id selector
2. Attribute priority issue: ID has a higher priority than class. We have an example in the code below.
3. It is convenient to reference JS and other client scripts. If you want to perform script operations on an object in the page, you can define an ID for it. Otherwise, you can only find it by traversing the page elements and specifying specific attributes. , this is a relative waste...
The correct answer on the third floor This explanation is very good
For example:
1. # is the ID selector. This is less used in defining styles
2. . is the category selector
3. Tag selector. For example, the element p tag style identifies all p-related elements in html. The content uses the style you defined
4. Descendant selector For example, ul and li .ul li{} Then the style of all li under ul will have the effect you defined
These comparisons Commonly used ones. If you want to see the details, you can input "css selector" in Baidu. The introduction is very detailed
1
The styles starting with "." can be referenced multiple times by class in the html page.
Just google it on Baidu and you will know