tags:

views:

1567

answers:

3

Hiya,

I hope this is a simple one, but I can't seem to be able to crack it quickly...

I've got a 2 column layout, with the content in the right column being dynamic and ajax driven. So the page height changes depending on what is in the right column.

I want to have a small flash file (400px x 200px) bolted on to the bottom of the page, but underneath column 1.

That's easy. The problem is.. I want the flash to have a negative top margin of -200px, so it doesn't get stuck out all on it's own. This also reduces the wasted white space.

<div id="container">
<div id="col_1" style="float:left; padding-bottom:200px;">Some static content</div>
<div id="col_2" style="float:left">AJAX content</div> 

<div style="clear:left"></div>

<div id="flash_container" style="margin-top:-200px;>
 <object>Flash file</object>
</div>

I've simplified the code quite a lot, but you should see what i mean. Simple 2 columns, clear the columns, bung a negative margin on the flash div. Works fine in IE6, Safari, Fails miserably in Opera, Firefox and Chrome.

Can you apply a negative margin "through" a clear?

All help appreciated ;)

+1  A: 

Here you go:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

<html>
<head>
</head>
<body>
    <div id="container" style="position: relative;">
        <div id="col_1" style="float:left; padding-bottom:200px; background-color: #235124;">Some static content<br />Another line</div>
        <div id="col_2" style="float:left">AJAX content</div>   

        <div style="clear:left"></div>

        <div id="flash_container" style="margin-top: -200px; position: absolute;">
                <object>
                    <param name="movie" value="boxheadrooms.swf">
                    <embed src="boxheadrooms.swf" width="550" height="400">
                    </embed>
                </object>
        </div>
    </div>
</body>
</html>

Requires an extra div to wrap it all in but it is required to enable the relative positioning.

Ignore the extra tags, flash objects and background colours I added, they were just to make the problem clearer to me when I was trying to understand what was happening.

Pheter
Absolute positioning "solves" the posted example, but will lead into trouble if there is content that follows flash object in the real document. This content will clash with the absolute positioned object that does not reserve any space for itself.
buti-oxa
Thanks :D This works on my code nicely. The flash is also the last object within the containing div, so it doesn't break the page at all.
hfidgen
As flash objects are of a fixed size you could simply add a margin-top that == the value of the height of the .swf file.
Pheter
A: 

Yes, you can. Negative margin will put your flash container div up there. The question is, how its content should behave.

I guess that if you replace your flash object with long text, you will see that the text, while starting "up there", still wraps around the floats.

Try replacing padding-bottom with margin-bottom or changing the display property of your flash object element.

buti-oxa
A: 

Wrap the two columns in a div and use overflow:hidden to clear the float. Use clear:both and position:relative to get the flash div to move to the left and overlay the two columns.

I added the background colors and heights so I could see where the divs are placed.

   <div id="container">
        <div style="overflow:hidden;">
         <div id="col_1" style="float:left; padding-bottom:200px;background-color:#c00;">Some static content</div>
         <div id="col_2" style="float:left;height:300px;background-color:#0c0;">AJAX content</div>
        </div>

        <div id="flash_container" style="margin-top:-200px;position:relative;clear:both;background-color:#ccc;height:100px;">
         <object>Flash file</object>
        </div>
    </div>
Emily