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.
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!
- Related Videos
- Related Articles
- Ask / Related Q&A
- CSS Web Design
- 7 Vital Knacks of Professional Web Designer While Designing Creative Website
- The Top Ten Sticky Issues In Web Design
- Web Design – The Benefits Of Simplicity
- Shooting Up Sales with a Web Design Team
- Using CSS in Web Design
- Where Can I Find Good Web Design Advice?
- Do You Need Dreamweaver in Order to Learn Web Design?




For Optimum Internet Marketing Keep Your Internet Presence Updated
By: Phyllis Zimbler Miller | 27/11/2009Your overall internet presence is very important for driving traffic to your website in order to achieve your internet marketing objectives. Yet, as you increase your presence on social media platforms, article directories, HubPages, Squidoo, YouTube, etc. you may be sending out mixed signals if your profile on all these different locations isn't consistent with your website positioning -- your brand.
Get Across Your Marketing Message with These Internet Marketing Tools
By: Phyllis Zimbler Miller | 27/11/2009The Internet offers an array of tools that can help you get across your marketing message and create a relationship between you and your potential clientele.
The New Google Comparison Ads
By: Ryan Frank | 27/11/2009Google recently launched its new ads service, the Google Comparison Ads tool. It is in its development stages still, and only available to businesses in the mortgage and finance sectors, but if successful, there’s a good chance that the tool will expand to cover other industries. So what does the tool do, exactly?
Rain Nutrition- Legit or Scam
By: Curtis Royse | 27/11/2009Is Rain Nutrition a scam or a legitimate opportunity? Read this article to discover the truth about this new MLM company.
Quick and Simple Overview on Webhosting Services
By: Ani K | 27/11/2009In the present internet world, if we think of something we can get it with in no time. It is possible because of the ease of access to the internet where one can search for anything and can get the best result. A company or an organization tries every possible...
Backlinks Are Powerful For A Top Ranking At Google
By: jamiehanson | 27/11/2009If you want to grab a top ranking at Google for a keyword that you target, you need backlinks for your website.
How to download online videos from youtube
By: jamiehanson | 27/11/2009While browsing on the Internet, you often come across several types of video streaming. Some online videos may be informative, whereas a few others may be just general, like a dance sequence or some dialogue recitation, a few other video streaming may include your favorite star performance while some may contain some comedy clippings and there are endless online videos that you may love to watch it again and again.
6 Strategies To Use When Podcasting
By: Stacey Zimmerman | 27/11/2009Pod casting seems very popular nowadays; it increases its popularity as long as the demand of the listeners and viewers for a potential podcast. So it becomes a competition, fighting to be the best choice. We always wish for a good number of visitors, likewise you are thinking and planning on editing your podcast so that it will stand out among massive number of podcast.
Ringtones and Copyright - What is the Status?
By: Christine Anderssen | 19/04/2008 | TechnologyHistory 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 | TechnologyCell 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 | InternetHosting 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 | MarketingIt 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 | InternetThe 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 | InternetCorporate 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.
7 Reasons a B2b Company Should Have a Website
By: Christine Anderssen | 29/10/2007 | MarketingCorporate B2B websites are not the most glamorous animals, but can a company really afford to be without one?