I have a a parent div that spans the width of the browser with padding at each side. Then I have 2 floating divs inside this parent. They are both set to float left. The first one has a set width and the second one I want to span the rest of the parent thats left over. When I put a background color on the second floating div it only shows up as the width of the text that is in the div. how can I get it to span the left over from the first floating divs with.
UPDATE
Ok here is a jsfiddle showing the setup.
JSFIDDLE LINK
The div that has a background that is red should span the rest of the parent even when you scale your browser.
Given that you want the second of the child
divelements to be the full remaining-width of the parent, you’ve no need tofloatit. Given the following mark-up:And CSS:
This seems to give the effect you’re looking for: JS Fiddle demo, though tested only in Chromium 17 on Ubuntu 11.04.
Edited in response to comment from OP, below:
The problem is that the
float-ed element is taken out of the document’s flow, and the seconddiv(.titlein your JS Fiddle) extends ‘behind’ it.To prevent that you need to both remove the
floatfrom the second div (it’s still there in the link you posted) and also give amargin-leftto the.titleelement, in order to prevent it taking the full width:JS Fiddle demo.
If you’re unable to give a
margin-leftfor any reason, you could, instead, useheight: 100%;on thefloat-eddiv(.time), although this is problematic due to the padding (given that the height of the element is defined-height + padding):JS Fiddle demo.
To correct the
heightproblem, in compliant browsers, you could use thebox-sizingCSS property to include thepaddingin theheight:JS Fiddle demo.