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 736795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:38:47+00:00 2026-05-14T07:38:47+00:00

I have a DIV container with several inner DIVs layed out by floating them

  • 0

I have a DIV container with several inner DIVs layed out by floating them all left. The inner DIVs may change width on certain events, and the containing DIV adjusts accordingly. I use float:left in the container to keep it shrunk to the width of the inner divs. I use float:left in the inner divs so the layout is clean even when their contents change.

The catch is that I want the DIV container width and height to remain constant, UNLESS a particular event causes a change to the inner widths. Conceptually I want to use float on the inners for the layout benefit, but then I want to “fix” them so they don’t float around. So if the container is 700px wide, I want it to remain so even if the user narrows the browser window. I’d like the container, and it’s internal DIVs to just be clipped by the browser window.

I sense this can all be done nicely in CSS, I just can’t quite figure out how. I’m not averse to adding another container if necessary…

Since the only desired layout changes are event-based, I am also willing to use a bit of JS. But is this necessary? (And I’m still not sure I know what to modify: container dimensions? inner floatiness? other?)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <style type="text/css">

      #canvas {
        overflow:auto;   /* for clearing floats */
      }

      #container {
        float:left;   /* so container shrinks around contained divs */
        border:thin solid blue;
      }

      .inner {
        float:left;   /* so inner elems line up nicely w/o saying fixed coords */
        padding-top:8px;
        padding-bottom:4px;
        padding-left:80px;
        padding-right:80px;
      }

      #inner1 {
        background-color:#ffdddd;
      }

      #inner2 {
        background-color:#ddffdd;
      }

      #inner3 {
        background-color:#ddddff;
      }

    </style>
  </head>
  <body>
    <div id="canvas">
      <div id="container">
        <div id="inner1" class="inner">
        inner 1
        </div>
        <div id="inner2" class="inner">
        inner 2
        </div>
        <div id="inner3" class="inner">
        inner 3
        </div>
      </div>
    </div>
    cleared element
  </body>
</html>
  • 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-14T07:38:47+00:00Added an answer on May 14, 2026 at 7:38 am

    If I understand you correctly, what you could do is to get rid of the floats, and lay out using display:inline-block. That way, as long as you ensure there are no spaces or newlines between the inner-divs it will be treated as a single word by the layout engine, and will stay on a single line (thus enlarging the containing <div> and/or overflowing if needed. You can use min-width and text-align:center for some stylistic improvements. Spacing between the elements can be created by using margin attributes on the inner <div>s.

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

Sidebar

Related Questions

I have several outer divs, all of them contain 3 inner divs class1 class2
I have a container DIV which contains several block-DIVS. Every block-DIV contains SPAN items
I have a div container inside which there are several child divs with css
I have a container div with the following CSS: #container { position:relative; overflow:hidden; width:200px;
I have this container div whose width I would like to set according to
I have a webpage with a div which contains several other divs WITHOUT an
I have a page with a container div that holds three additional divs as
You need to have several 200px wide DIVs (.item) inside a 620px wide DIV
I have: I have several web pages both with this outline: <body> <div id=container>
I have a container that has several divs with content. i need to be

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.