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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:13:44+00:00 2026-05-23T04:13:44+00:00

I’m working on a web app where a large number of thumbnails will be

  • 0

I’m working on a web app where a large number of thumbnails will be displayed. I would like to achieve the behavior used in iTunes when displaying albums as thumbnails in a grid (not Coverflow). The idea is that the thumbnails have a fixed size, while the container div has a fluid width. As many thumbnails as possible should be fit in one row, and the margin between the thumbnails should be adaptive so that the thumbnails always take up 100% width of the container.

See the two images below:

Four thumbnails making use of the full width

A slightly smaller window where three thumbnails fit, still taking up the full width by increasing the margin

If it is possible to achieve this with CSS, that is preferable, otherwise I would appreciate JavaScript/jQuery solutions as well.

  • 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-23T04:13:44+00:00Added an answer on May 23, 2026 at 4:13 am

    Made some small improvements to the script given by Alex, to fully suit my needs. Now the first thumbnail on each row doesn’t get a left-margin, and the last thumbnail on each row doesn’t get a right-margin, so that the thumbnails really make us of the full width of the container div. Also used jQuery’s .outerWidth() instead of .width() to retrieve the width of the thumbnail, so that you can use borders etc. without compromising the calculation. Now the script also run as soon as the DOM is loaded, to calculate the proper margin from the beginning, and not only when the window is re-sized.

    Here’s the new script:

    <script type="text/javascript">
    $(document).ready(calculateThumbnailMargin);
    $(window).resize(calculateThumbnailMargin);
    
    function calculateThumbnailMargin() {
    
        // Define a minimum margin
        var minimumMargin = 20;
    
        // Get the outer width of the thumbnail (including padding and border)
        var thumbWidth = $('.video-thumbnail-container').outerWidth();
    
        // Calculate how man thumbnails can fit on one row
        var numberofdivs = $('#content-area').width() / thumbWidth;
        numberofdivs = Math.floor(numberofdivs).toFixed(0);
    
        if (numberofdivs >= $('.video-thumbnail-container').size()) {
            numberofdivs = $('.video-thumbnail-container').size();
        };
    
        // Calculate the remaining width of the row  
        var widthleft = $('#content-area').width() - (thumbWidth * numberofdivs);
    
        // Calculate the proper margin to use
        var margin = (widthleft / (numberofdivs - 1)) / 2;
    
        // Check that the margin is not less than the minimum margin
        if (margin < minimumMargin) {
            // Use one less thumnail on each row
            numberofdivs = numberofdivs - 1;
    
            // Calculate the remaining width of the row  
            widthleft = $('#content-area').width() - (thumbWidth * (numberofdivs));
    
            // Calculate the proper margin to use
            margin = (widthleft / (numberofdivs - 1)) / 2;
        }
    
        // Add the proper margin to each thumbnail
        $('.video-thumbnail-container').attr('style', 'margin-left:' + margin + 'px; margin-right:' + margin + 'px');
    
        // Remove the left-margin on the first thumbnail on each row and the right-margin on the last thumbnail on each row
        for (i = 0; i < $('.video-thumbnail-container').size(); i = i+numberofdivs) {
            $(".video-thumbnail-container:eq(" + i + ")").css('marginLeft', 0);
            $(".video-thumbnail-container:eq(" + (i + numberofdivs - 1) + ")").css('marginRight', 0);
        }
    }
    

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have some data like this: 1 2 3 4 5 9 2 6
I am writing an app with both english and french support. The app requests

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.