Welcome to WebmasterWorld Guest from

Forum Moderators: not2easy

Message Too Old, No Replies

preventing div from wrapping underneath another div

7:07 pm on Jun 26, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:July 11, 2003
votes: 0

I'm having a problem with a simple 2-column layout.

Here's the css:

body {margin-top: 0px; margin-left: 0px;}

#colA {float: left; background-color: #333300; width: 60%; padding-top: 20px;}

#colB {float: left; background-color: #999966; border: solid 1px #999966; width: 170px; margin-top: 100px; margin-left: 50px; text-align: center;}

and the markup...

<div id="colA">
Some text here.

<div id="colB">
<img src="image.jpg" align="right" border="0" alt="logo" width="170" height="118">

and the problem...

Unless the browser window is maximized (or at least nearly so), colB drops down underneath colA. I'd rather have colA and colB remain side by side no matter what, and if a horizontal scrollbar becomes necessary, so be it.

FWIW, I've also tried floating colB right as well.

I'm sure I'm missing something basic here. All clues are welcome.


6:29 am on June 27, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 18, 2007
votes: 0

You'll probably want to just do it with absolute positioning. Just realize that absolutely positioned items don't take up flow... so you might have trouble putting stuff underneath it unless it has a fixed height. (and then there's javascript if it isn't fixed height)
If you don't need anything under it at all, then it's not an issue at all :)

Instead of float:left, for colA you give position:absolute;top:0;left:0
and for colB position:absolute;left:60%;top:0

The only other option I can think of by keeping the floats, is to use javascript (can't be done with current CSS technology because it's a mix of percentage and pixels) to size a container div to be equal to the width of the two other divs (including border margin and padding).

[edited by: Xapti at 6:31 am (utc) on June 27, 2007]

2:50 pm on June 27, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:July 11, 2003
votes: 0

Worked like a charm. Many thanks.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members