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

  • Home
  • SEARCH
  • 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 7009479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:52:02+00:00 2026-05-27T21:52:02+00:00

I have a bunch of inline-block elements over several lines which I’d like to

  • 0

I have a bunch of inline-block elements over several lines which I’d like to center horizontally. The inline-block elements all have the same fixed size, but I’d like the centering to be able to handle page resizing and adding or removing elements.

I’ve stripped down the html/css and removed the attempt at centering for clarity. It’s at http://jsfiddle.net/fe25H/1/

If you resize the results window so that the third inline-block element drops down, the container fills the width and we get this:

-----------------BODY------------------
|                                     |
||-------------CONTAINER-------------||
||-INLINEBLOCK---INLINEBLOCK--       ||
|||____________||____________|       ||
||-INLINEBLOCK--                     ||
|||____________|                     ||
||___________________________________||
|_____________________________________|

rather than this:

-----------------BODY------------------
|                                     |
|   |----------CONTAINER---------|    |
|   |-INLINEBLOCK---INLINEBLOCK--|    |
|   ||____________||____________||    |
|   |-INLINEBLOCK--              |    |
|   ||____________|              |    |
|   |____________________________|    |
|_____________________________________|

edit based on ptriek’s answer regarding a JavaScript solution:

Ptriek’s code was a useful starting point; it works for the specific case, but not the general one. I’ve mostly rewritten it to be more flexible (see http://jsfiddle.net/fe25H/5/).

  • 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-27T21:52:03+00:00Added an answer on May 27, 2026 at 9:52 pm

    After thinking a bit about it, I agree with Wex’ comment above.

    So I fiddled a JavaScript solution (jQuery) – I’m not an expert on this, so the code might be improved – but I guess it does exactly what you need:

    var resizeContainer = function () {
        var w_window = $(window).width();
        var w_block = $('.inlineblock').width();
        if (w_window < w_block * 3 && w_window >= w_block * 2) {
            $('.container').width(w_block * 2);
        } else if (w_window < w_block * 2) {
            $('.container').width(w_block);
        }  else {
            $('.container').width(w_block * 3);
        } 
    };
    
    
    $(document).ready(resizeContainer);
    $(window).resize(resizeContainer);
    body {
        text-align:center;
    }
    .container {
        display: inline-block;
        background-color: #aaa;
        text-align:left;
    }
    .inlineblock {
        display: inline-block;
        width: 200px;
        height: 200px;
        background-color: #eee;
    }
    <div class='container'>
        <div class='inlineblock'></div>
        <div class='inlineblock'></div>
        <div class='inlineblock'></div>
    </div>

    http://jsfiddle.net/ptriek/fe25H/4/

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

Sidebar

Related Questions

I currently have a bunch of inline-block div s stacked up horizontally. When the
I have a bunch of elements like the following: <div class=droppableP id=s-NSW style=width:78px; height:63px;
We have bunch of Domain Entities which should be rendered to an html format,
I have a bunch of perfmon files that have captured information over a period
I have a bunch of old classic ASP pages, many of which show database
Currently, I have bunch of triggers that do the same thing. This is copy-pasted
I have page1.html and page2.html. There are bunch of inline links on page2.html, on
week DKK id=radio2 value=75 /> I have bunch of these div entry generated by
Does Java and/or Spring have the concept of properties? I have bunch of domain
I have a bunch of files that I need to be able to transport

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.