Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,200,242 members, 7,974,167 topics. Date: Sunday, 13 October 2024 at 05:25 PM

Elementary Lessons In Css - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Elementary Lessons In Css (741 Views)

MUST SEE: How To Place 2 Divs Side By Side In CSS / If You Are Very Good In Css, Html,flash & Animation / Let's Learn Something 4 - Setting Div Heights In Css (2) (3) (4)

(1) (Reply)

Elementary Lessons In Css by yawatide(f): 8:17pm On Sep 09, 2008
As some of u may know, i love to google for stuff. Every now and then, I will find a site that makes me want to view source because its full of crap.  Rather than tell myself what is wrong with the site so that it stays with me only, I have decided to share my thoughts on this board, from now on.  Here are my lessons in CSS, having just looked at a horrible site:

1) When dealing with hex codes and u hv something like this: #aabbcc or any combination such that the pairs have the same value (like #ffffff), you can save yourself a few keystrokes by doing this: #abc or #fff

2) When dealing with margins and paddings, you can save yourself a few keystrokes by doing this:
margin: 10px 5px 4px 5px; as opposed to:

margin-top: 10px;
margin-right: 5px;
margin-bottom: 4px;
margin-left: 5px;

Note the order. Also, if the top and bottom, and the left and right, hv the same values, you can abbreviate further like so:
margin: 10px 3px (top-bottom: 10px, left-right: 3px)

Even better? If all 4 attributes are the same value, you just type the value once.  So you could have "margin: 5px;" where all attributes are 5px each.

3) If dealing with a zero-value measurement, don't bother putting the units.  So instead of 0px, just type "0". It's not mathematics where zero is a number.

4) Name your classes/IDs not for what they do but for what they are:
Don't name your DIV "bold".  Name it "header" and then add a "font-weight: bold" attribute to it.

5) For browser consistency, zero out all margins, paddings, etc.  Then add back your XHTML elements, with classes/IDs, then add paddings, margins to those:
Initially, you would have: p {margin: 0; padding: 0; } for instance.  Then you have p#introduction { margin: 5px; padding: 3px; }

Once the values are reset, the actual values you use will be consistent across browsers. Besides, it sure beats using CSS hacks that might end up not working after IE10 comes out.

6) Don't add a gazillion " " tags to your code.  Handle white space using margin/padding attributes

7 ) Name your classes/IDs with words that make sense.  Trust me, you will thank yourself when you have to go back to the code a month from now:
Dont say: "p.style2". What the hell does style2 mean?

That's it for now.  If you guys have anything to add, feel free to do so.
Re: Elementary Lessons In Css by WebMonk(m): 2:50pm On Sep 10, 2008
<removed>

(1) (Reply)

Domain Search Tool Needed / Need Help! Placing Ads On My Website A.s.a.p! / I require competent hands for this project

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.