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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:54:06+00:00 2026-06-12T18:54:06+00:00

I have a centred div with floating elements in it, each element has the

  • 0

I have a centred div with floating elements in it, each element has the same height and width and is floating. When the div is resized, there is always a gap on the right side where there isnt enough space to fit another element. What I want is for the div to only expand when it can fit another element rather than just have a space there. Is that possible?
enter image description here

  • 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-06-12T18:54:08+00:00Added an answer on June 12, 2026 at 6:54 pm

    CSS3 Solution

    Using some @media query calls (so there is a practical limit to how large one might want to go), yields a good result on CSS3 browsers. See this fiddle (full screen), which uses this (just for example) code:

    HTML

    <ul class="container">
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul> 
    

    CSS

    @media screen and (min-width: 122px) {
      .container {width: 120px;}
    }
    
    @media screen and (min-width: 242px) {
      .container {width: 240px;}
    }
    
    @media screen and (min-width: 362px) {
      .container {width: 360px;}
    }
    
    @media screen and (min-width: 482px) {
      .container {width: 480px;}
    }
    
    @media screen and (min-width: 602px) { 
      .container {width: 600px;}
    }
    
    /* you need to decide just how far to take it */
    
    .container {
        margin: 10px auto;
        overflow: hidden;
        border: 1px solid red;
        height: 210px;
    }
    
    li {
        width: 100px;
        height: 50px;
        background: cyan;
        float: left;
        margin: 10px;
    }
    

    Also, it is possible that you or other users might find this helpful.

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

Sidebar

Related Questions

I have a centred fixed width content div , and if there isnt enough
I have a container div which is centred at 50% of the page width.
I have a div ( #main ) that has been centred to the middle
I have a div inside another div. The outer div has a starting width
I have a relatively positioned div within a centred div of width 50%... I
i have a HTML page with a centered div of 780px width and 8400px
I have a website with a centered fixed width div (the div is centered
I have a fixed-width, relatively positioned, and centered #content div (shown as the outer
I have a div called target which is centred and displayed over a google
How do I verically center the content of floating div (which height I don't

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.