CSS writing skills

Source: Internet
Author: User

Nettuts provides Five CSS writing skills to translate the core idea.

1. CSS reset/Reset

You may need to know what is CSS reset first. Then how can I reset the CSS.

You can copy Eric Meyer reset, Yui reset, or other CSS reset, but you should change it to your own reset based on your project.

Do not use * {margin: 0; padding: 0 ;}. I personally love it. The original author mentioned that using this sentence does not apply to some elements, such as single-choice buttons. However, there is no single-choice button in my blog. If so, just reset the single-choice button again.

 2. Arrange CSS in alphabetical order

Not in alphabetical order

 

Div # header H1 {
Z-index: 101;
Color: #000;
Position: relative;
Line-Height: 24px;
Margin-Right: 48px;
Border-bottom: 1px solid # dedede;
Font-size: 18px;
}

  In alphabetical order

 

Div # header H1 {
Border-bottom: 1px solid # dedede;
Color: #000;
Font-size: 18px;
Line-Height: 24px;
Margin-Right: 48px;
Position: relative;
Z-index: 101;
}

The reason is that a property can be better found. I personally think it's okay, and the difference is not too big. However, it may be suitable for you.

3. Better CSS Structure

CSS comments are used to group CSS objects. This structure is clear and facilitates collaborative design.

 

/***** Reset *****/
Xxxxxxx {XXXXX}
XXXXX {XXXXX}
/***** Layouts *****/
Xxxxxxx {XXXXX}
XXXXX {XXXXX}

 4. Maintain consistency

It is better to write all the attributes of a selector in one row or one row for each attribute. You think OK is good.

 

IV # header {float: Left; width: 100% ;}
Div # header Div. Column {
Border-Right: 1px solid # CCC;
Float: rightright;
Margin-Right: 50px;
Padding: 10px;
Width: 300px;
}
Div # header H1 {float: Left; position: relative; width: 250px ;}

For example, I personally like to write a line, because writing a line in each row will make the entire document feel too long and it is inconvenient to find it. What if you like to write one row but send it to the other team, but he prefers each row? In fact, it is very simple to take the CSS for W3C verification. It will have a result that will be automatically converted to each row.

5. Mark first and then CSS

I don't quite understand this. In general, it is easier to write CSS after marking HTML. For example, if I write a page, first write a basic tag structure.

 

<Body>
<Div id = "wrapper">
<Div id = "Header"> <! -- End # header -->
<Div id = "Container">
<Div id = "content">
</Div> <! -- End # Content -->
<Div id = "sidebar">
</Div> <! -- End # sidebarr -->
</Div> <! -- End # container -->
<Div id = "footer">
</Div>! <-- End # footer -->
</Div> <! -- End # wrapper -->
</Body>

Then, we try to make good use of the sub-selector, instead of adding a selector to the sub-Selector as soon as possible.

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.