Master the use principle of ID and class in CCS

Source: Internet
Author: User
Keywords us layout nbsp;

Are you learning CSS layouts? Are you still unable to fully master the pure CSS layout? There are usually two situations that hinder your study:
&http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp;
The first possibility is that you have not yet understood the CSS Process page principle. Before you consider the overall performance of your page, you should consider the semantics and structure of the content before adding CSS to the semantics and structure. This article will show you how to structure HTML.

Another reason is that you have no idea what CSS statements to translate into the very familiar performance layer attributes (such as cellpadding, Hspace, align= "left", etc.).

When you've solved the first problem, and you know how to structure your HTML, I'll give you a list of the original performance attributes in place of CSS.

When we first study the Web page, we always think about how to design, consider the pictures, fonts, colors, and layout options. Then we use Photoshop or fireworks to draw and cut into small pictures. Finally, all the design restores are displayed on the page by editing the HTML.

If you want your HTML page to be in CSS layout (css-friendly), you need to go back and start thinking about the semantics and structure of your page's content, regardless of the appearance.

Appearance is not the most important. A well-formed HTML page can appear with any appearance, CSS Zen Garden is a typical example. CSS Zen Garden helps us finally realize the power of CSS.

CSS beginners are often bothered by a problem when they start using the div layout: When defining a property, is it using an ID, or is it using class? Here I talk about the principles of using ID and class in my work. Hope to help beginners.

Principle of use of IDs

We know that ID is unique, that is, the ID in the entire XHTML can not be duplicated, so we write the page, the large structure with ID, such as: logo, navigation, subject content, copyright, according to the naming code, respectively named #logo, #nav, #contenter, # Copyright。 There is another situation: we have to use JS to effect a layer to achieve a certain effect, with the ID. This is also determined by the uniqueness of the ID.

The use principle of class

Class is universal in CSS definition and can be reused infinitely, which also embodies the superiority of div layout. Class is commonly used within structs, and the benefit of this is that it facilitates late maintenance and modification of site code, which makes all classes a child or grandchild of the ID.

Also note that try not to let class include IDs, such as. ff #childer {...}, which is obviously undesirable and does not conform to the writing habit. Also introduced in front of good writing habits, the code to write norms, and other colleagues to cooperate, so that later maintenance is very good.

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.