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
https://forums.phpfreaks.com/topic/241179-clear-float-problem/
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
https://forums.phpfreaks.com/topic/241179-clear-float-problem/#findComment-1238857
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
https://forums.phpfreaks.com/topic/241179-clear-float-problem/#findComment-1238950
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.