I have two divs in my layout. I am trying to put them side by side, by giving the first div (div1) float:left .
This step works out well , but when i give the left padding to my second div (div2), mozilla is not showing it correctly. In IE its looking well, but mozilla is doing a mess. The left padding of ‘15px’, it is taking from the far left corner of the screen, and not recoginizing the space that div1 has used. Is there any solution for it?
<body>
<div id=“div1”>fsd</div><!–div1 ends here –>
<div id=“div2”>Some text Some textSome textSome textSome textSome textSome text </div>
<!–div2 ends here –>
</body>
Floats are removed from the flow and therefore elements alongside floats will almost act as if teh float isn’t there and margins, padding, borders and background colours will slide under the float as though the float wasn’t there at all.
The foreground content is moved out of the way by the float but margins and padding on the static content will still refer to the containing block and not the floated element.
IE is adding the padding because you have given the element a “layout” using height. This makes the element take note of the float and applies padding from the floated element instead. You can get the same effect in other browsers by applying overflow other than visible to to #div2 (#div2{overflow:hidden}).
Probably the easiest solution is simply to apply the margin from the floated element as that will push foreground content away.
yes it works, if i give overflow:hidden to div2. thanks for your solution.
but at the same time i am so confused, that the floats getting removed from the flow. that is so weird and illogical. is there any reason, why the floats are getting removed, even after we specify for it.
and second thing, what is the connection between 'overflow:hidden ’ and ‘float’. why are the floats getting displayed with this particular tag?
These things are so confusing. every time i decide to design a div based layout, and such problmes occur. and then i switch again to table based layouts.
The default height you have set on the div element triggers hasLayout in IE, to make good browsers behave like IE they need an overflow setting other than the default visible, e.g.:
div{ height:150px; overflow:hidden}
This makes a fluid static box clear its edges from float edges on its inside and outside, and its margin/padding will not slide under the adjecent float.
[EDIT]
Oops…
Apparently I had this tab unrefreshed for a long time. :)[/EDIT]
but at the same time i am so confused, that the floats getting removed from the flow. that is so weird and illogical.
No, it’s totally logical because floats do exactly what their name says and they “float”.
They are not contained by anything and just “float” around. That’s why the “clear” property is available so that floats can be cleared and normal service can be resumed under the float.
Floats weren’t really meant for columnar layout which is why you have to jump through a few hoops to get them to work as columns but they are very flexible and will work well if coded correctly.
and second thing, what is the connection between 'overflow:hidden ’ and ‘float’.
The connection has nothing to do with floats but the fact that overflow (other than visible) causes a container to take care of its boundaries and this creates a rectangular block that will also take note of floats and stop collapsing margins also. (It’s the same effect that “haslayout” has on elements in IE.)
I’m having a similar issue with two DIVs. In IE they both show up, but in Mozilla the second one does not. I tried a few of the suggestions but have not had any luck. Here is my code.
Can you post css and html rather than asp. Please post the code that you get from view source when the file is run and we’ll take a look and see what’s going on.
Paul, figured it out. I took out the following line in the CSS for the right graphic and it now shows up. I now have another issue because of that, but at least I got this solved.
Yes IE6 doesn’t implement background-attachment:fixed properly but other browsers do. A fixed position is always relative to the viewport (at all time) and not the element or parent that contains it.
I should have noticed you had that property in there but as I didn’t have images to look at and so I overlooked it