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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:34:07+00:00 2026-06-18T03:34:07+00:00

I have a container (image gallery) that is max-width:80%. Inside, images are floated left

  • 0

I have a container (image gallery) that is max-width:80%. Inside, images are floated left forming columns and rows. As you shrink/expand the browser window, more or fewer images fit into each row and there is typically a “remainder” at the end of each row, when there is not enough space to fit another full image:

http://jsfiddle.net/vladmalik/DRLXE/1/

I’d like the container to expand or contract to exactly hug however many floats fit into a column (so there is never a yellow remainder to the right). Can this be done with CSS?

HTML:

<section>  
   <div></div>  
   <div></div>  
   <div></div>  
   <div></div>  
   <div></div>  
</section>  

CSS:

div {  
   width: 100px;  
   height: 100px;  
   float:left;  
   background: red;  
}  

section {  
   margin: 0 auto;  
   max-width: 80%;  
   background:yellow;  
   overflow: hidden;  
}  
  • 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-18T03:34:08+00:00Added an answer on June 18, 2026 at 3:34 am

    I’m thinking you might be able to do this with a jQuery .length() of div that constantly re-calculates the needed width and height based on window size. So if…

    div {
      width: 100px;
      height: 100px;
      float: left;
    } 
    

    Then…

    $(document).ready(function(){
        changeSize();
    });
    
    function changeSize(){
        var length = $('div').length(); //let's say is 12 
    
        var windowwidth = $(window).width(); //let's say it's 1000px, 
    
        if (length >= 10 && windowwidth >= 600px){ 
            $('section').css('width', '300px'); 
            $('section').css('min-height', '400px'); 
        }
        else if {
            //Some more sizing code...
        }
    }
    
    $(window).resize(function() {
        changeSize();
    });
    

    You would need to set the conditions in the if statements based on your needs, but this method should do it.

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

Sidebar

Related Questions

I have a container that has images inside. I use CSS columns and media
I have an image gallery that, at the moment, displays only images. I would
I have a photo gallery that is organised like this: .container %li %a{src: image.src}
I have a container that contains an image that I need to drag from
I have an image <div class='container'> <img src='../images.jpg' alt='images' /> </div> I want to
I have a big <div /> container that has an image as a background.
I have an image gallery that is dynamically loaded with php. In chrome it
I have a page that displays images at a set width. The height is
I have a vertical image gallery of this sort: <div class=image-container> <div class=nav> <div
I have an image container with a caption and when I hover over it

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.