ArticlesBase.com - Free Articles Directory
Free Online Articles Directory
07.09.2008 Sign In Register Hello Guest
Email:
Password:
Remember Me 
forgot your password?


7 CSS Layout Tips

Author: Christine Anderssen Author Ranking Bronze | Posted: 05-05-2008 | Comments: 0 | Views: 94 | Rating:  (117) Article Popularity - Blue (?) Got a Question? Ask.
Sign Up Now!

The most difficult thing in CSS to get right is the layout of your site. Here are a couple of tips dealing just with that. Some of these tips are not exactly new, or rocket science, but hopefully they will save someone a bit of bother somewhere!

Tip 1 : Clear out the default padding and margin settings before you start working.
Different browsers have different default margin and padding sizes so you want to start with a clean slate, so to speak. Use this command:

*

{

margin: 0;

padding: 0;

border: 0;

}

to clear all default margin and padding settings. Also note the border, which is set to 0. Please note that if you do this, you will also get rid of the pesky purple border round click-able images, although some people argue that the purple border is necessary for accessibility and usability. But lots of people do not like the purple border round images, and this is one way that you can get rid of it in one fell swoop without having to set img border=0 for each image (which is against the strict markup rules in any case).

Tip 2 : To center your layout, use a container div to contain all your content
Declare it as follows:

#container

{
margin: 0 auto;
width: xxxpx;
}

There are a couple of points here to take note of. DO NOT declare the width to be 100%. This defeats the whole object since you will just have to declare the sub elements within the container and then center THEM using margin : 0 auto. This is VERY BAD since it means that instead of declaring the central layout once, you will have to declare it in multiple places for each element within your container.

Tip 3: Work from the top down
Literally start working on your CSS layout starting from the top most elements in your design, as well as the 'top' elements in your HTML, such as the body, as well as your main containers.

Declare your CSS commands on the highest level possible and try and declare something once only and let it cascade throughout. Only override the commands at a lower level when strictly necessary. This prevents a verbose CSS file that is difficult to maintain and understand. For example, if you have { margin : 0 auto} settings on each and every sub div within your container - you are in trouble.

Tip 4 : Document what you are doing and use Firebug and the Firefox browser to debug
You are not writing your CSS code just for yourself, some day some poor sod will have to debug it. Make numerous comments inside your CSS file to explain why you are doing things in a specific way.

Fitting in with this, you might find yourself having to fix someone else's CSS more often than you think (or even your own, for that matter). Use the Firebug add-on for Firefox to debug your CSS. This is a life-saver with regards to giving you an insight into exactly where your design might be broken and why.

The only problem with this is that your design might work perfectly in Firefox, but not in IE5, IE6 or IE7. This brings us to the next tip.

Tip 5 : Decide which browsers you are going to build your CSS for and test from the start
Some purists insist on making sure that your website work for all possible browsers, others only make it work for the 'major' browsers. How do you know exactly which browsers are used the most? Once again W3 Schools come to the rescue.

On the following page, you can see which browsers are the most popular: http://www.w3schools.com/browsers/browsers_stats.asp. From this page you can see that something like IE5 is only used by about 1.1% of browsers. It is up to you whether you consider it worthwhile to build your CSS to be compatible with this browser, or whether you are just going to test your compatibility with IE6, IE7 and Firefox, for example. Whatever you do, when you start building your CSS, start from the top, and test each and every setting in each of the browsers as you go along. There is nothing worse than building a perfect website in Firefox, then finding out right after you have coded a 1000 line css file that it is broken in IE6. To then debug and fix your code after the fact is a nightmare.

Tip 6 : Here is an embarrassing little tip for fixing your CSS in IE6 or IE7
Let's say your design works perfectly in Firefox, but is broken in IE6. You cannot use Firebug to determine where the problem might be since it WORKS in Firefox. You do not have the luxury of using Firebug in IE6, so how do you debug an IE6 or IE7 stylesheet? I often found that it helps to add {border : 1 px solid red} or {border : 1 px solid purple} to the problematic elements. This way you can often see why certain elements do not fit into the space available. It is an embarrassing little tip since it is so primitive and simple, but it works!

Tip 7 : Understand floats
Floating of elements is essential to understand, especially in the context of getting your floated elements to work in the different browsers!

Basically elements such as divs are floated to the left or the right (never to the top or the bottom, only sideways). Here are a couple of things to take into consideration with floated elements. Each floated element must have an explicit width specified. If you are making use of floated divs to create a 3 column or a 2 column layout, rather specify the widths in terms of percentages rather than fixed widths, and if you do use percentages, make sure that the percentages do not add up to 100%, this will often cause the right most column to drop below the rest, clearly indicating that you are trying to fit something into the available space that is too wide for it. Rather use percentages that add up to slightly below 100%, such as 25%, 49%, 24% for a left column, middle column and right column.

Floating elements can be extremely complex to understand and it is worth while to spend some time on good sites that provide specific guidelines and tips, such as the Position Is Everything website.

Conclusion
These CSS tips for layout should hopefully save you some time and effort when you next have to panel-beat a table-less design into submission!

Rate this Article: Current: 5 / 5 stars - 2 vote(s).

Article Tags: Web Design, Css, Style Sheet

Article Source: http://www.articlesbase.com/internet-articles/7-css-layout-tips-404167.html

Print this Article Print article   Email to a Friend Send to friend   Publish this Article on your Website Publish this Article   Send Author Feedback Author feedback  
About the Author:

Christine Anderssen is the owner of Tailormade4you, a web design and hosting company in South Africa, catering for small business website owners. Visit our site on http://www.tm4y.co.za/10-strategies.html to download your free guide on how to make your website really work for you and bring in more customers to your business.

Submitting articles has become one of the most popular means of generating quality backlinks and targeted traffic to your website. Join us today - It's Free!

Article Comments

Comment on this article Comment on this article
Your Name
Your Email:
Comment Body
Enter Validation Code: Captcha


Related Articles

5 Things Every Web designer Should Know
By: Hilco Van Der Meer | 30/04/2006 | Business
5 things every webdesginer should know. Do you know all of these?

Making Better Web Graphics That Grab your Attention and Load Fast
By: John Catalfamo | 08/04/2007 | Computers
The art of web design is more than just your software it is also the ability to learn and grow in your art. My hope is that this information will help you do this.

Web Design With Simplicity Principle
By: tisha | 22/10/2007 | SEO
We usually think over how could we get good traffic, good results from search engines. Simple web design is a very effective idea for it. We will discuss here how can it be much beneficial for client as well as the owner of the website.

CSS and Tables: The hype and the trends
By: Deepak Sharma | 21/12/2005 | Technology
Before tables came along, the web was a pretty dull place. Using tables for layout opened up new vistas of possibilities of visually ?designing? a page.

Div Vs Table
By: Lee Grears | 27/04/2007 | SEO
Is web 2.0 costing the table tag its life?

CSS Buttons Instead of Image Files
By: Tim Whiston | 17/03/2008 | Web Design
Often a Website owner decides to “dress up” their menu display by using button graphics instead of plain text links. It’s a great idea to give your navigation more punch, but I recommend you avoid going with image files for your buttons and instead choose a simple CSS (Cascading Style Sheets) layout.

Effective Website Design
By: tisha | 22/10/2007 | SEO
A real website designer always works to produce best results. His main aim is always to attract the idle audience and give them satisfactory results. There are lots of key factors by which a successful website can be designed like analysis, good planning, brief and easy to read content, simple and effective design, keeping eye on present competition, testing and evaluation.

The Shrek Model of Web Design
By: Christine Anderssen | 25/11/2006 | Internet
Here is a web design theory : websites are like onions, you see, since websites have layers. And ogres are like onions, since ogres have layers. Websites are designed by web designers. Ergo - web designers are like ogres.

Got a Question? Ask.

Ask the community a question about this article:

Frequently Asked Questions

ZabaSearch and ZabaSphere
By: Jonesy | 05-08-2008
Is it safe to use ZabaSearch or ZabaSphere?  Could they violate my privacy?

What's the best performing code or script for ...
By: LAPIII | 03-08-2008
What's the best performing code or script for creating web apps?

How to change the white background
By: Fawzia Humperdink | 30-07-2008
how to change the white background

Putting moving things on to my dreamwever 8 or flash
By: angel444 | 29-07-2008
Hi: I have a complete set of Dreamweaver 8 MX2004 which comes with flash and an additional software which I forget the name of. I also have a sofware program on my computer that makes 3-D pictures. One of the 3-D is that you are able to put your pictures into a book and on to each page.  The book automatically opens and moves through each page showing different pictures. How can I get this on to my Dreamweaver 8 where I am building a web site.  In addition I was surfing the net and came across this web site www.heathersanimation.com. I would like to take one of the figures off of there and be able to put this moving figure on to my web site. How is this done? Any information you could give me would be greatly appreciate. My e-mail address is valleyofthelight@aol.com many thanks

Youtube videos don't play on my computer, why?
By: HEMPIST69 | 23-07-2008
Actually no videos of any kind will play.  The video and sound are choppy and it stops and starts every 4 to 5 seconds.  I have windows xp on a new laptop.  It's never played videos since I bought it 2 weeks ago.  First I thought my connection to the internet wasn't strong enough but even when I am plugged in it doesn't play.  Any advice?

How do I set up my own PHYSICAL DNS??
By: Reloaded | 20-07-2008
How do I set up my own PHYSICAL DNS?? I want a physical one, as in Modem, Firewall and Server, not a virtual one.

Q&A Powered by:
Powered by Yedda 

Latest Internet Articles

Blog Directories Can Bring Big Traffic to Your Blog
By: Jay Gaulard | 07/09/2008
If you're blogging without pinging blog directories, you're missing out. Blog directories help your blog get more traffic.

Top 3 Work From Home Online Jobs You Can Benefit From
By: Mal Keenan | 07/09/2008
Are you fed up with all the crappy home business scams online? Yeah, me too! Discover how you can earn $1000s in residual income from home today, with little cash investment...

Shaklee MLM Home Business - Grandfather of All MLM Companies
By: Richard van Beek | 07/09/2008
Shaklee is the grandfather of all the MLM companies. The fifty year model is something that most MLM companies strive for, but few will ever accomplish. Here is a short business review

How to Build Trust & Increase Conversions by Using Voice Overs on Your Sales & Landing Pages
By: Stephanie Ciccarelli | 07/09/2008
What if you could up the ante and reach those prospects on a heightened, more emotional level? You can! How? Use surprisingly affordable professional voice overs on the landing page or sales page. Adding a voice over isn't just another bell or whistle to your website, it is an ingeniously persuasive method of grabbing a browsers attention and literally overpowering the conversation in their head.

What the Heck is Web 2.0 Exactly?
By: Evelyn M Anderson | 07/09/2008
Web 2.0 compared to 1.0. Tools and ideas working together to make the internet a more user friendly and easier world to maneuver.

Article Writing Techniques- 5 Ways to Improve Your Article
By: Jeff Schuman | 06/09/2008
I have successfully been using article marketing now for over three years. Of course I am not the only one! Article marketing has become one of the most popular ways to promote an Internet business because of the low promotion costs involved. Let me share with you 5 ways that you can improve your articles and help ensure that they get read.

Do You Really Need Software for Affiliate Marketing?
By: William Hutchinson | 06/09/2008
While you do not necessarily need affiliate marketing software, it is extremely beneficial to purchase software for affiliate marketing. You can benefit greatly from having software to help you construct a web site and blog together.

Should You Get a Merchant Account, or Not?
By: Andrew Jamaz | 06/09/2008
Should you get a merchant account or use a third party processor? Which will save you money? Which is easiest? Which is the best, long-term option?

More from Christine Anderssen

Why Buy a Persian Carpet
By: Christine Anderssen | 24/08/2008 | ECommerce
Here are some reasons why you should buy a Persian Carpet - for its beauty and for its value.

Male Yeast Infection - Four Ways in Which a Yeast Infection Poisons Men
By: Christine Anderssen | 20/08/2008 | Science
Are you a guy that suspects that you might be suffering from a yeast infection? Or are you just feeling tired and listless and itching in the wrong places? Read more about how your body will react to a yeast infection.

Ringtones and Copyright - What is the Status?
By: Christine Anderssen | 19/04/2008 | Technology
History of ring tones - a quick overview as well as a look at some of the legal and copyright implications.

Cell Phone Ring Tones - Convert Your Own Ring Tones
By: Christine Anderssen | 22/03/2008 | Technology
Cell Ringtone converters can convert any piece of music into a ring tone, or help you to convert ring tones from other phone formats into the right format for your phone

Web Hosting Overselling
By: Christine Anderssen | 10/01/2008 | Internet
Hosting overselling means that a hosting company is selling much more of its resources than it has available, on the understanding that not everyone will utilize the hosting packages to the full. This article looks at whether hosting overselling is a good thing or a bad thing, or whether it does not really matter.

Start Up Website Design
By: Christine Anderssen | 28/12/2007 | Marketing
It is often tempting to spend as little as possible on a website when a company is just starting up. This article reviews the costs that go into a website and points out the pitfalls of going for a too cheap website option.

Why Internet Marketing is Similar to Weight Loss
By: Christine Anderssen | 16/11/2007 | Internet
The Internet Marketing and the Weight Loss industry have some disturbing parallels. This article is a tongue in cheek look at why.

Corporate Blogging - Pitfalls and Guidelines
By: Christine Anderssen | 12/11/2007 | Internet
Corporate blogging can be fraught with problems and pitfalls, although it does offer a way to spice up a corporate website. Here are some guidelines that corporates should consider if they are thinking of allowing their employees to blog as corporate bloggers.

Article Categories






Give Feedback

Sign up for our email newsletter

Receive updates, enter your email below