Jump to content

Clear float problem


garry27

Recommended Posts

This problem really annoys me...

 

Why is it when you float a block element, the block element that follows has to float (possibly in the same direction only) in order for it's top margin to register? It doesn't matter if you set the top margin to 100000em and set clear both the second element just won't shift unless you float it. Adding an intermediary block to clear the float doesn't help either.

 

e.g.

 

<div style="background-color:#00C ; float:left; width:200px; height:100px;"/></div>

<div style="background-color:#00C ; clear:left; margin: 10000000px 0 0 40px; width:200px; height:100px;"/></div>

Link to comment
Share on other sites

you might want to have a read in the css manual on the property float. this is exactly what it (float) is suppose to do in your code given(also see this).

Run the code below and see what i mean. (notice the word moo)

mooo<div style="background-color:#00C ; float:left; width:200px; height:100px;"></div>

<div style="background-color:#00C ; clear:left; margin: 200px 0 0 40px; width:200px; height:100px;"></div>

or try

    <div  style="background-color:green; overflow:hidden;">
            <div style="background-color:#00C ; float:left; width:200px; height:100px;"></div>
            <div style="background-color:#00C ; clear:left; margin: 200px 0 0 40px; width:200px; height:100px;"></div>
    </div>

 

Just another thing. your markup was invalid this didn't cause your problem, but it still is invalid to  do the following:

<div/></div>

see your code (<div style="background-color:#00C ; float:left; width:200px; height:100px;"/></div>)

Hope this helps.

Link to comment
Share on other sites

you might want to have a read in the css manual on the property float. this is exactly what it (float) is suppose to do in your code given(also see this).

Run the code below and see what i mean. (notice the word moo)

mooo<div style="background-color:#00C ; float:left; width:200px; height:100px;"></div>

<div style="background-color:#00C ; clear:left; margin: 200px 0 0 40px; width:200px; height:100px;"></div>

or try

    <div  style="background-color:green; overflow:hidden;">
            <div style="background-color:#00C ; float:left; width:200px; height:100px;"></div>
            <div style="background-color:#00C ; clear:left; margin: 200px 0 0 40px; width:200px; height:100px;"></div>
    </div>

 

Just another thing. your markup was invalid this didn't cause your problem, but it still is invalid to  do the following:

<div/></div>

see your code (<div style="background-color:#00C ; float:left; width:200px; height:100px;"/></div>)

Hope this helps.

 

I've read the links you posted but I'm still confused. Would you mind clarifying please how I can fix the problem

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.