Example analysis of three style methods (Id,class,style) in CSS

Source: Internet
Author: User
There are three ways we can apply styles to an object, such as div,span,table.

1: Use # To define the style, and use the ID to apply a style to the object.
Cases:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> 

2: Use. Define the style and apply a style to the object using class.
Cases:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> 

3: Do not define style, apply style to object directly using style.
Cases:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> 

The effect of using these three methods is the same, but we need to be aware of the priority issues between these three methods.
What if we were to define a style for an object using all three of these methods at the same time?
For example, we first define a #style {font-size:12px;} Define another one. STYLE {font-size:14px;} Finally, use the style= "font-size:16px" on the object; The code is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> 

In this case, the browser applies a style to the object based on the priority of three ways, that is, Style>id>class. In the above example, the text in the Div will be displayed as 16px in size.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.