This simple tutorial is a great for those getting to grips with t..
Iam going to warn you that if you’re a web developer and you watc..
Very cool effect that could be used for an intro or as an enter button for any web site...
Create animated eyes that blink, wink and following the mouse pointer using Flash...
In this crazy new world of web 2.0 some designs call for some bright, shiny gradient butto..
Panoramic images the easy way with Photoshop PhotoMerge
Creating Panoramic images from your photos is easier than you think, when you know how. So..

Here’s an article for beginners in the practice of CSS Layouts, my reason for writing this one came from remembering the difficulty I once had position elements in CSS. After many frustrating attempts with relative and absolute position techniques I finally found the holy grail of CSS the “Float” attribute!
Ok so I’ve started to design my web site and have learnt how to position things using the position: relative and position: absolute; heres some examples of these below:

This works well, for basic positioning, but when your layouts become a little more complex as they always tend to do, tyring to position div's within div's using this method can become a real struggle.
Troubles can start when elements positioned as absolute can often position themselves to the entire page as apposed to the containing div, which can sometimes become a real nightmare.
Other simple tasks such as creating multiple divs in-line with each other for navigations etc can also involve many un-nessisary left right positioning values. So save yourself the trouble and crack open a can red bull and give yourself some wings!
The float attribute allows you to position objects to either the left or right of your page <div> tag, for example using the following section of code creates a page with two boxes one on the left hand side the other on the right.

<div style="float: left; width: 50%; height: 100px;"></div>
<div style="float: right; width: 50%; height: 100px; "></div>
Now this is the cool thing about Float, unlike the other positioning attributes it makes it so easy to position elements right next to each other. For example if your wanted to create a navigation menu that spanned left to right with say 5 different boxes, the Float attribute makes this so simple.
When you create a floated div tag using the following code: float: left; providing it fits into the length of the page it will position this flush with the side of a previous floated element, see below.

If you then wanted to start your next element below this new set of navigation boxes, simply add the “clear” setting to the next tag followed by the side setting of the previous float tag, the example above also shows how this set of elements was started on a newline using the clear: left; setting.
float: left; clear: left;
Also using the following setting on your element will drop it onto the next line underneith any left or right floated elements:
float: left; clear: both;
Float: center; does not exist
Don’t ask me why this has never been added to the CSS library but it is easily fixed, if you want to center a div within a float tag simply create a div without the use of the float attribute and use the following margin settings:
<div style="float: left; width: 600px;">
<div style="width: 300px; margin-left: auto; margin-right: auto;"></div>
</div>
Float inside a Float
When adding a div tag with the float attribute within another div try to remember that the preceeding tag must also have the float attribute applied to it. Think of this tip as a fix for when you float something and it dosent seem to take effect on your layout.
<div style="float: left; width: 600px;">
<div style="float: left; width: 300px;" ></div>
</div>
Comments (21)
Posted by: aja on 13/04/2008
"How do you determined how far from the top or bottom it is?" there are numerous ways, changing the bottom and top padding or margins are most popular
Posted by: totem on 07/03/2008
How do you determined how far from the top or bottom it is? tatltnokio@hotmail.com
Posted by: Anonymous on 21/02/2008
very good
Posted by: i am on 08/02/2008
thtgt
Posted by: tgththt on 08/02/2008
good details
Posted by: selvasekhar on 08/02/2008
this is a test
Posted by: tester on 03/02/2008
how about float in table, is same as above??
Posted by: lunark1d on 23/12/2007
I agree with Shaileshmistry, it's a great tutorial but I think it would be clearer to see what the code does by using screen shots as well as seeing the difference by using floats vs relative and absolute positioning!
Posted by: Anonymous on 18/10/2007
10px for uuuuu ;)
Posted by: whatever on 09/10/2007
Very good article. floats really confuse newbies.
Posted by: Serenity on 04/10/2007
thanks .. that was a great tutorial .. I am looking forward for new tutorials by you in future.
Posted by: Symbiote on 07/09/2007
Thanks - my page looked great in IE but in firefox my second div was off screen to the right. Using clear : left in the 2nd div fixed the problem.
Posted by: Will Scarlet on 26/08/2007
Awsome! Keep it up.
Posted by: N. L. on 21/08/2007
nice tutorial....expecting some more !!
Posted by: mowglitech on 18/08/2007
grear 10x
Posted by: eruin on 14/08/2007
Thanks, Very usefull
Posted by: Toon on 03/08/2007
it works great. thanks again : )
Posted by: Shaileshmistry on 31/07/2007
Would of been nice to see some examples of what the code did. Either from screenshots or actual html/css examples.
Posted by: Anonymous on 27/07/2007
nice tute, to the point and has helped out heaps
Posted by: Aaron Souter on 20/07/2007
Thanks that is great
Posted by: Paul Roberts on 18/07/2007
Graphics techniques that can double your click-thru rate with Google Adsense..
The secret to good CSS layouts rests with the Float attribute. Using float instead of rela..
A great list of freeley available video encoding/converting software..
A large selection of expert tips and advice to help you design and market the perfect web ..
The low-cost answer to keeping your CD's/DVD's clean and functional...
A look at the things I've done over the past few months that have dramatically increased m..
Send to a friend
Thanks that is great