Home >Web Front-end >HTML Tutorial >May I ask why some css files start with . and some start with #? Is it possible to use both? _html/css_WEB-ITnose

May I ask why some css files start with . and some start with #? Is it possible to use both? _html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:08:241731browse

Is there a difference between the two? The beginning refers to the first line of the css file


Reply to the discussion (solution)

. Indicates class # Represents Id
For example:


css:.a{}

css:#a{ }

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

These are all style selectors


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!

1. Duplicate IDs are 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. , this is relatively wasteful...
1

Starting with . is the class selector

Starting with # is the id selector

1. Duplication is not allowed in web standards ID, such as 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. , this is a relative waste...
The correct answer on the third floor This explanation is very good

Simple and easy to understand~ . Represents class #Represents Id

For example:


css:.a{}

css:#a{}

These are style selectors


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

It looks like this


It's very simple. "#" specifies the ID reference. The ID name is in the same CSS file and is unique, that is, the same name can only be used once.

The styles starting with "." can be referenced multiple times by class in the html page.

Just google it on Baidu and you will know

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn