Graphic Design Forum and Web Design Forum  

Go Back   Graphic Design Forum and Web Design Forum »Web Design Forum »CSS Forum

Notices

CSS Forum Cascading Style Sheets (CSS) and XHTML Forum


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 13-03-2008, 09:16 AM
jontywagener's Avatar
Experienced Member
 
Join Date: Oct 2007
Location: South Africa
Gender: Male
Posts: 161
Default understanding css float

hi guys,

i need some help in understanding how the float works in css. i see that quite a few people use it for layout and it seems to work. i can float sections but i cant have anything below them because it is not displayed correctly (usually underneath the floated section).

is there a way to make float work?
please help.
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote

  #2 (permalink)  
Old 13-03-2008, 10:19 AM
Junior Member
 
Join Date: Mar 2008
Location: Kent, UK
Posts: 24
Default

Hi JW!

First off, can I say (in a nice way!) this is really a rather fundamental question to look for a quick answer to in a forum. If you're having trouble with the basic concept of floats, you're probably at an early enough stage in your learning of CSS that the best thing to do is get a good introductory book and work through it. My favourite for beginners is 'Head First HTML with CSS and XHTML', by Elisabeth and Eric Freeman. Don't be put off by the title, thinking you already know HTML: implementing designs with CSS is about developing your HTML and CSS in concert; you need to understand how both interact.

Having said that, I'll have a go at answering your specific question:
  • Web pages (HTML) are just text. It is the browser that renders the web page and makes it something you might like to look at.
  • Browsers have default rules about how to render stuff like Lists, Paragraphs, Headings etc.
  • CSS provides additional instructions that the browser takes note of (with greater or lesser accuracy) when rendering the page. You can override a lot of the default rendering with CSS.
  • One of the most fundamental concepts in rendering a page is 'flow'. This means that the browser starts at the top of the HTML file and, barring any other instructions in the HTML or CSS, lays the page out from top to bottom, following two rules:
  1. 'Block' elements, such as Paragraphs and DIVs go below one another down the page.
  2. 'Inline' elements, such as Links, SPANs and IMGs go one after another across the page, until they reach the page width and wrap onto the next line.
  • 'Float' is most usually applied to block elements, when we want to 'break the rules' and put two block elements next to eachother across the page, contrary to the normal rendering rules.
  • When you float an element, you take it out of the normal flow of the page. This means that other block elements can go next to it, but also that from the perspective of the page as a whole it now has no height, allowing other things to go beneath it.
  • You can force a later element to 'look for' and go below floated elements by applying the 'clear' property (clear:left; clear:right; or clear:both; ).
So, two practical rules:
  1. To make sure following elements 'clear' the bottom of your float, use 'clear'.
  2. To make sure a containing element (a DIV, usually) expands vertically to contain a floated element, the containing element must also be floated.
Have fun, and do take a look at that book. It will help you loads in getting up to speed.
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #3 (permalink)  
Old 13-03-2008, 10:32 AM
jontywagener's Avatar
Experienced Member
 
Join Date: Oct 2007
Location: South Africa
Gender: Male
Posts: 161
Default

ok, thanks. i understand it a bit better. sorry for creating such a vague post :)

i will have a look at that book also.

J
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #4 (permalink)  
Old 14-03-2008, 02:27 PM
rossable's Avatar
sarcastic encouragement, brilliant!
 
Join Date: Oct 2007
Location: IN, USA
Gender: Male
Posts: 1,055
Default

if you need to print a web page though floats will break it.
i avoid them whenever possible, or write a special print section in my CSS that hides the floats that don't matter for print (ie. navigation, adds, etc.)
__________________
http://justross.com/
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #5 (permalink)  
Old 17-03-2008, 10:01 AM
flashwiz's Avatar
Stylish Member
 
Join Date: Jan 2007
Location: North Yorkshire, England
Gender: Male
Posts: 612
Default

Hi Jonty,

There are a number of places for you to learn more about floats in CSS. They are not as complicated as they may first seem. One of the best places i can recommend in the first instance is Listomatic: css.maxdesign.com.au - CSS resources and tutorials for web designers and web developers

This should give you a good insight into how floats work, unfortunately some of the information you have been given is incorrect (sorry rossable) floats will NOT break when printing.

Any problems just shout..
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #6 (permalink)  
Old 17-03-2008, 12:35 PM
tommylogic's Avatar
f*ck yeah it validates!!!
 
Join Date: Apr 2007
Location: Virtually Everywhere
Gender: Male
Posts: 5,904
Default

Quote:
Originally Posted by flashwiz View Post
... unfortunately some of the information you have been given is incorrect (sorry rossable) floats will NOT break when printing.

Any problems just shout..
WOW!!! Talk about laying down the gauntlet. You are very correct though.

In Ross's defense, I believe if you float incorrectly or don't clear floats properly, that it won't always print as displayed. On the same note, it also won't always view in certain browsers as expected either..
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #7 (permalink)  
Old 17-03-2008, 12:43 PM
flashwiz's Avatar
Stylish Member
 
Join Date: Jan 2007
Location: North Yorkshire, England
Gender: Male
Posts: 612
Default

But if you dont clear floats properly then they wont show on the site correctly either, so you should know before it comes to printing that there is a problem :-)

Although didnt mean it in the way it maybe comes across... just didnt want the new person learning to be given wrong info.. :-) no offence Rossable...
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #8 (permalink)  
Old 17-03-2008, 02:10 PM
jontywagener's Avatar
Experienced Member
 
Join Date: Oct 2007
Location: South Africa
Gender: Male
Posts: 161
Default

thanks for the link flashwiz.
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
  #9 (permalink)  
Old 17-03-2008, 02:15 PM
flashwiz's Avatar
Stylish Member
 
Join Date: Jan 2007
Location: North Yorkshire, England
Gender: Male
Posts: 612
Default

No worries... im sure you will find lots of simple easy to understand tutorials in there...

Any problems, shout!
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati Share This Article & VoteReddit! Wong this Post!Stumble this Post!RSS Share on FacebookForum Netvibes Page
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Design Float spyros General Web Design Forum 4 12-12-2007 01:32 PM
Design Float - Digg Style Design Site Toon General Web Design Forum 8 24-09-2007 01:40 PM


All times are GMT. The time now is 10:31 AM.



Estetica Design Forum's Privacy Policy
Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0