Table of Contents
Chocolate curry
Home Web Front-end CSS Tutorial After reading this, everyone will understand the difference between class and ID selectors in CSS styles. Summary_Experience exchange

After reading this, everyone will understand the difference between class and ID selectors in CSS styles. Summary_Experience exchange

May 16, 2016 pm 12:06 PM
class css the difference style Selector

You can define your own selectors using the class selector and the identifier selector id.

The advantage of this is that you can represent the same HTML element differently depending on the class or id.

In CSS, the class selector is preceded by a half-width English period (.), and the id is preceded by a half-width English pound sign (#).

Looks like this:

#top { background-color: #ccc; padding: 1em } .intro { color: red; font-weight: bold; }
HTML with CSS connections use the attributes id and class. Like this:

Chocolate curry

This is my recipe for making curry purely with chocolate

Mmm mm mmmmm



The difference between id and class is that id is used on a unique element, while class is used on more than one element.

You can also apply selectors to a specific HTML element by placing the HTML selector in front, so p.jam { whatever } will be applied to paragraphs with class "jam".


An id name is usually uniquely defined in a page, so it is usually recommended to use class when defining css on a page, so that you can reuse your css. Leave the id for the most needed use JavaScript for html elements, etc.
Statement of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

deepseek What is the difference between r1 and v3 version deepseek What is the difference between r1 and v3 version Feb 19, 2025 pm 03:24 PM

deepseek What is the difference between r1 and v3 version

Does Bitcoin have stocks? Does Bitcoin have equity? Does Bitcoin have stocks? Does Bitcoin have equity? Mar 03, 2025 pm 06:42 PM

Does Bitcoin have stocks? Does Bitcoin have equity?

Summary of FAQs for DeepSeek usage Summary of FAQs for DeepSeek usage Feb 19, 2025 pm 03:45 PM

Summary of FAQs for DeepSeek usage

What is the difference between pre-market and after-market trading? Detailed explanation of the differences between pre-market and after-market trading What is the difference between pre-market and after-market trading? Detailed explanation of the differences between pre-market and after-market trading Mar 03, 2025 pm 11:54 PM

What is the difference between pre-market and after-market trading? Detailed explanation of the differences between pre-market and after-market trading

Why is Bittensor said to be the 'bitcoin' in the AI ​​track? Why is Bittensor said to be the 'bitcoin' in the AI ​​track? Mar 04, 2025 pm 04:06 PM

Why is Bittensor said to be the 'bitcoin' in the AI ​​track?

Is there any difference between South Korean Bitcoin and domestic Bitcoin? Is there any difference between South Korean Bitcoin and domestic Bitcoin? Mar 05, 2025 pm 06:51 PM

Is there any difference between South Korean Bitcoin and domestic Bitcoin?

Pepe bought and sold out in a big way, is MUTM a smarter investment in 2025? Pepe bought and sold out in a big way, is MUTM a smarter investment in 2025? Mar 03, 2025 pm 07:09 PM

Pepe bought and sold out in a big way, is MUTM a smarter investment in 2025?

Vertical proxy: Application scenarios and interpretation of disruptive potential of encryption native proxy Vertical proxy: Application scenarios and interpretation of disruptive potential of encryption native proxy Mar 04, 2025 am 10:21 AM

Vertical proxy: Application scenarios and interpretation of disruptive potential of encryption native proxy

See all articles