Forum Moderators: not2easy

Message Too Old, No Replies

Floating a fixed width div to the right of a variable with div

         

eRAZOR

10:03 am on Aug 27, 2008 (gmt 0)

10+ Year Member



I'm trying to float a fixed width div to the right of a variable with div. The purpose is to implement an ad container that's positioned to the right of the main content.

Example:
<div style="float: left;>
Content
</div>
<div class="width: 160px; height: 600px; vertical-align: top; text-align: left; float: right;">
<img src="/img/simulate_ad_160x600.gif"/>
</div>
<div class="clear"></div>

The problem is that as soon I float the left div, the divs get corrently positioned but the left content div loses it's auto-sizing.

wizs

11:24 am on Aug 27, 2008 (gmt 0)

10+ Year Member



Just a thought and perhaps a solution. It's difficult to see all that's going on without looking at your code fully.

Can you not add an ID to the advertisement image and then float the image right - or position it top right and add some margin to add some space?

E.g.

<img src="/img/simulate_ad_160x600.gif" width="160" height="600" id="advert" />

Add position:relative to your variable width div style. Then add a style for the advert:

#advert {
position: absolute;
top: 0;
right: 0;
}

This should position to the advert to the top right, then you can add margin and padding as you see fit.

#advert {
float: right;
}

This may also work. I'm no expert in CSS but I've dabbled quite a bit, so this may be something to try. Others who are more experienced may have a better solution.

swa66

12:09 pm on Aug 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Floating both your content and your ads is going to be harder than needed.

Try to only float your ad.

Use margins on the main content if you do not want it to wrap in under the ad.

A footer might need to be forced to clear the float as needed.