Home >Web Front-end >HTML Tutorial >DIV CSS learning--about ID and CLASS_html/css_WEB-ITnose

DIV CSS learning--about ID and CLASS_html/css_WEB-ITnose

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-24 12:31:261067browse

DIV CSS Learning--About ID and CLASS The method I recommend is to use underlines between words, or the method of splicing words. Because CSS is case sensitive. As you can see, all the download files I provide you are processed in lowercase.

We first deal with the style of the sidebar. After analysis, we can know that the sidebar has four parts. We divide these four parts into four layers:




China Network Management Forum










Here we have ID and CLASS, so there are My friend is about to ask, when should ID be used and when should CLASS be used?

 ID represents uniqueness and will only appear once in this page. We use it to represent the structure of the layout;
CLASS represents a group (class) or a class with the same properties. Elements, they can share styles and will appear multiple times on the page.

Since the styles of member login, site information, page standards and content words in these areas will be the same, we put them in a group.

But sometimes, when we need to set different styles for the elements in these layers, how do we do it? For example, the words "member login" are bolded with 14px, and the others are bolded with 12px. How do we write CSS? See the code below?
.bar_title {font-size:12px;font-weight:bold}
#login .bar_title {font-size:14px}

 #login .bar_title represents the login ID The CLASS under the layer is the style of the bar_title element, which means that the style can be customized for certain elements in a targeted manner. #login .bar_title When the style of font-size:14px is set separately, it also inherits the style of the .bar_title group (class), which is font-weight:bold, bold.

China Network Management Alliance




title2


Here, I want to set the text style of title1 to 14px, red, and change the text style of title2 The style is 10px, green, both title1 and title2 need to be bold, DIV adds a red 1px border, SPAN adds a green 1px border, the style can be written like this:
.title {border:1px solid #f00} /*Default is 1px red border*/
span.title {border-color:#0f0}
.title a {font-weight:bold}
div.title a {font-size:14px ;color:#f00}
span.title a {font-size:12px;color:#0f0}

As you can see, using CLASS allows many elements to share the same style. Depending on the TagName of the elements, different styles can be customized for each element. I think everyone should have a deep understanding of when to use ID and when to use CLASS!
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
Previous article:Some suggestions for DIV CSS layout_html/css_WEB-ITnoseNext article:Some suggestions for DIV CSS layout_html/css_WEB-ITnose

Related articles

See more