Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1565 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     HTML/XHTML/DHTML/CSS :

Best way to work with floating?

Thread title: Best way to work with floating?
Closed Thread    
    Thread tools Search this thread Display Modes  
06-04-2008, 07:27 AM
#1
penguinburner is offline penguinburner
Status: Junior Member
Join date: Sep 2007
Location: Australia
Expertise: Programming, UX
Software:
 
Posts: 80
iTrader: 3 / 100%
 

penguinburner is on a distinguished road

  Old  Best way to work with floating?

If I have a 2 column design, I'll often float one side left, the other right, then be forced to add a blank div that clears it underneath. Is there a better way, without having to add arbitrary elements that only clear? Maybe there's a bit of css I'm missing out on

Thanks

06-04-2008, 09:06 AM
#2
rochow is offline rochow
rochow's Avatar
Status: Member
Join date: Oct 2006
Location: Australia
Expertise:
Software:
 
Posts: 297
iTrader: 4 / 100%
 

rochow is on a distinguished road

Send a message via MSN to rochow Send a message via Skype™ to rochow

  Old

<rant>

This goes for everyone: you never have to use a clear div. Ever. I slap people that use clear divs. I go Jackie Chan on them. I eat them for breakfast. I hate clear divs, they are SO obviously unneeded, and yet all these "pros" use clear divs like there's no tomorrow. Even worse, people who use <hr /> because they think they are clever (haha, it's not a clear div, so technically it's fine!!!) No, you aren't clever. No, it's not fine.

</rant>

Now with that out of the way...

Just add "clear:both" onto the next element. Or if you are clearing to bring the background down, add "overflow:hidden" for FF, and for IE6 "height:1%" or "width:100%" or "width:123px" does the trick. You will get the hang of it pretty quickly. It's hard for me to explain to you how I know what to use - it's just second nature to me, I don't even think about it. Try in this order:

1) Add "clear:both" to the next element (still not working, go to step 2)
2) Add "overflow:hidden" to the existing elements (still not working, go to step 3)
3) Set a width on existing elements (Same as "overflow:hidden" for FF, but for IE6. Only used in certain circumstances. still not working, go to step 4)
4) Float 'em all

Because even I'm struggling to figure out WTF I wrote above if you show me your example I'll show you how to do it with no clear divs. I think that'll be easier for everyone!

http://www.robertnyman.com/2007/04/1...ues-explained/

06-04-2008, 12:22 PM
#3
Liam is offline Liam
Liam's Avatar
Status: Member
Join date: Dec 2007
Location: Liverpool, UK
Expertise:
Software:
 
Posts: 287
iTrader: 0 / 0%
 

Liam is on a distinguished road

Send a message via MSN to Liam

  Old

I use overflow:hidden most of the time.

I also, always try to code the site so I can float everything on the left, this does make things a lot easier in the long run.

I do use float:right when I need to (in place of absolute positioning usualy) but for setting up a column design, I float all columns to the left.

06-04-2008, 11:16 PM
#4
penguinburner is offline penguinburner
Status: Junior Member
Join date: Sep 2007
Location: Australia
Expertise: Programming, UX
Software:
 
Posts: 80
iTrader: 3 / 100%
 

penguinburner is on a distinguished road

  Old

I always sort of knew I didn't need a clearing div but I usually just used it because it's quicker. Sometimes I clear:both on the following element, but sometimes the two floats are the last in the parent element, and they'll still wreck the rest of the page:

Code:
<div>
   <div id="left"></div>
   <div id="right"></div>
</div>

<p></p>
Basically, the <p> would be weird still. I'll experiment

06-27-2008, 12:14 PM
#5
aeryes is offline aeryes
aeryes's Avatar
Status: I'm new around here
Join date: Jun 2008
Location:
Expertise:
Software:
 
Posts: 9
iTrader: 0 / 0%
 

aeryes is on a distinguished road

Send a message via ICQ to aeryes Send a message via MSN to aeryes Send a message via Skype™ to aeryes

  Old

I always have
.clear { clear:both; }
with me, so when ever I need to clear after floating it's easy to add clear to the next element without altering it's class, like:

<div class="left"></div>
<div class="right"></div>
<div class="nextElement clear"></div>

06-27-2008, 03:58 PM
#6
Liam is offline Liam
Liam's Avatar
Status: Member
Join date: Dec 2007
Location: Liverpool, UK
Expertise:
Software:
 
Posts: 287
iTrader: 0 / 0%
 

Liam is on a distinguished road

Send a message via MSN to Liam

  Old

Originally Posted by aeryes View Post
I always have
.clear { clear:both; }
with me, so when ever I need to clear after floating it's easy to add clear to the next element without altering it's class, like:

<div class="left"></div>
<div class="right"></div>
<div class="nextElement clear"></div>
I use this, and a mix of the clearfix, with the IE8 js library to force IE6 to behave nicely, which lets me use most of the pseudo classes in ie6, so clearfix works in ie6 aswell, and I can use :hover on any element

07-04-2008, 10:57 AM
#7
anishktrehan is offline anishktrehan
Status: I'm new around here
Join date: Jul 2008
Location:
Expertise:
Software:
 
Posts: 5
iTrader: 0 / 0%
 

anishktrehan is on a distinguished road

  Old

thanks for method

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed