Five tips for writing CSS

Source: Internet
Author: User

1. Arrange css in alphabetical order
Unalphabetically arranged:
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: you can better find a property.
2. Better css Structure
Css comments are used to group css. This structure is clear and facilitates collaborative design.
/***** Reset *****/
Xxxxxxx {www.sytm.net}
Xxxxx {xxxxx}
/***** Layouts *****/
Xxxxxxx {www.sytm.net}
Xxxxx {xxxxx}
3. Maintain consistency
It is better to write all the attributes of a selector in one row or one row for each attribute. If you like to write a line, because writing a line in each line will make the entire document feel too long and it is inconvenient to find it. However

Another person sent to the team, but he liked to arrange a row in each sentence. What should I do? 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.
4. Mark first and then css
It is not easy to write css after marking html. For example, to 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.
5. CSS Reset/Reset
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.
* {Margin: 0; padding: 0;} does not apply to some elements, such as single-choice buttons. However, if there are single-choice buttons, just reset them.

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.