You can't tell me example#2 can't find the right margin property faster. Sort your element attributes according to the alphabet. Consistent creation of your CSSwill help you save the time spent looking for a special attribute.
I know some people use this method to organize code, and others to organize it in another way, but in my company, we make a consensus decision that all the code will be organized in alphabetical order. It must be helpful to organize your code in concert with others. When I hit a cascading style sheet with properties that aren't sorted alphabetically I'll shrink every time.
3. The Organization
You should organize your stylesheets so that the relevant content is put together and it's easier to find what you want. Use more effective annotations. For example, this is how I construct my cascading style sheet:
/*****reset*****/
Removes the padding (padding) and margins (margin) of the element.
/*****basic elements*****/
Define the style of the basic elements: Body, H1-H6, UL, OL, A, p, etc.
/*****generic classes*****/
Define a simple style, as if one side of the float, remove the bottom margin of the element, etc.
Of course, most of them are irrelevant to the semantics we want, but they are necessary to handle code efficiently.
/*****basic layout*****/
Define basic templates: header, footer, etc. Help define the basic elements of a Web page layout
/*****header*****/
Define all Hearder elements
/*****content*****/
Define the elements in all content boxes
/*****footer*****/
Define all elements of footer
/*****etc*****/
Define additional selectors.
By annotating and grouping similar elements, you will find what you want faster.
4. Consistency
Whatever way you decide to write code, keep it consistent. I've been bored and tired of arguing about how to write all the CSS in 1 vs. multiple lines. There is no need to argue. Everyone has their own point of view, so choose a work style that you like and keep it consistent across all stylesheets.
Personally, I'm going to use the combination of the two ways. If a selector exceeds 3 properties, I will truncate it to write in a multiline way.
Div#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;}
So find the way you like to work and stay consistent.
5. Start from the right place
Don't try to approach your style sheet until you're done with the markup language.
When I am ready to split a Web page, before I create a CSS file, I need to preview and mark all the documents between the body and the Closed tab of the body. I will not add additional div, ID, or class selector. I will add some general Div, just like hearder, content, footer. Because I know these things are real.
By marking the document first, you will not encounter the doomed Divities 1 and Classitis 2 trouble!/*you only need to add in that stuff once your have begun to WR Ite the CSS and realize that you are going to need another hook to accomplish what for you are trying to achieve.*/(not translated in the original).
Uses the CSS child selector to specify child elements; Do not simply add a class or ID selector to an element mechanically. Remember that does not have a well-formed document (or tag structure) CSS is worthless.
Summary These tips can help me better write the CSS code. But that doesn't mean the end of the list, and then I'm going to bring something else to share with you.