I want to have two items on the same line using 'float: left' for the item on the left.
I have no problems achieving this alone. The problem is, I want the two items to stay on the same line even when you resize the browser very small. You know... like how it was with tables.
The goal is to keep the item on the right from wrapping no matter what.
So how to I tell the browser using css that I would rather stretch the containing div than wrap it so the the float: right;
div is below the float: left;
div?
example: what I want:
\
+---------------+ +------------------------/
| float: left; | | float: right; \
| | | /
| | |content stretching \ Screen Edge
| | |the div off the screen / <---
+---------------+ +------------------------\
/
Another option: Do not float your right column; just give it a left margin to move it beyond the float. You'll need a hack or two to fix IE6, but that's the basic idea.
Solution 1:
display:table-cell (not widely supported)
Solution 2:
tables
(I hate hacks.)
Wrap your floating
<div>
s in a container<div>
that uses this cross-browser min-width hack:You may also need to set "overflow" but probably not.
This works because:
!important
declaration, combined withmin-width
cause everything to stay on the same line in IE7+min-width
, but it has a bug such thatwidth: 100px
overrides the!important
declaration, causing the container width to be 100px.Wrap your floaters in a div with a min-width greater than the combined width+margin of the floaters.
No hacks or HTML tables needed.
When user reduces window size horizontally and this causes floats to stack vertically, remove the floats and on the second div (that was a float) use margin-top: -123px (your value) and margin-left: 444px (your value) to position the divs as they appeared with floats. When done this way, when the window narrows, the right-side div stays in place and disappears when page is too narrow to include it. ... which (to me) is better than having the right-side div "jump" down below the left-side div when the browser window is narrowed by the user.
The way I got around this was to use some jQuery. The reason I did it this way was because A and B were percent widths.
HTML:
CSS:
jQuery: