Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7593257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:07:26+00:00 2026-05-30T21:07:26+00:00

I have a a parent div that spans the width of the browser with

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:07:27+00:00Added an answer on May 30, 2026 at 9:07 pm

    Given that you want the second of the child div elements to be the full remaining-width of the parent, you’ve no need to float it. Given the following mark-up:

    ​<div id="parent">
        <div id="one">The first div, fixed width</div>
        <div id="two">The second, taking up the rest of the space.</div>
    </div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
    

    And CSS:

    ​#parent {
        width: 90%; /* adjust to taste */
        padding: 10px;
        background-color: #ffa; /* just to see where each element is in the document */
        overflow: hidden; /* to ensure the parent encloses the floated child div */
    }
    
    ​#one {
        float: left;
        width: 100px; /* whatever width you need */
        background-color: red; 
    }
    #two {
        background-color: #f90;
    }
    

    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:

    When I remove the float from my second div or in the jsfiddle example of mine .title the background fills the entire parent. Not sure what I’m doing wrong…

    The problem is that the float-ed element is taken out of the document’s flow, and the second div (.title in your JS Fiddle) extends ‘behind’ it.

    To prevent that you need to both remove the float from the second div (it’s still there in the link you posted) and also give a margin-left to the .title element, in order to prevent it taking the full width:

    .title{
        padding: 17px 20px 0;
        background-color: red;
        height:54px;
        margin-left: 200px;    
    }
    

    JS Fiddle demo.

    If you’re unable to give a margin-left for any reason, you could, instead, use height: 100%; on the float-ed div (.time), although this is problematic due to the padding (given that the height of the element is defined-height + padding):

    .time{
        padding: 17px 20px 0;
        float:left;
        margin-right: 20px;
        height: 100%;
        background-color: black;
    }
    

    JS Fiddle demo.

    To correct the height problem, in compliant browsers, you could use the box-sizing CSS property to include the padding in the height:

    .time{
        padding: 17px 20px 0;
        float:left;
        margin-right: 20px;
        height: 100%;
        background-color: black;
        box-sizing: border-box;
    }
    

    JS Fiddle demo.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main parent div that is .resizable(). One of it's child divs,
I have a div with multiple spans inside. The spans contain text that cannot
If you have a parent div that wraps a fixed height div and a
I have a function that prepends a li tag to a parent div just
I have one parent DIV inside parent DIV i have two DIV one in
There has to be a simple explanation for this. I have a parent <div>
I have this html: <div class=foo parent> <div class=child></div> </div> with some css: .foo{
I have the following table in my HTML: <div style=max-width:700px;> <table border=1> <tr><td colSpan=2>this
I have a #header div that is 100% width and within that div I
I have a parent div (container) that has a child div (inner) which also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.