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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:26:36+00:00 2026-06-11T15:26:36+00:00

I have a container div. Inside that container div are a number of smaller

  • 0

I have a container div. Inside that container div are a number of smaller divs that I would like to space out the width of the parent div while adding a gap between each. The number of inner divs will change.

I’m using this formula (containerWidth-(numberOfBars*gap))/numberOfBars to figure out each bar’s space and then trying jquery to modify the css dynamically.

I can’t get the width to change or get them to space out.

A fiddle is attached.

http://jsfiddle.net/MjrMq/

Thank you!

  • 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-11T15:26:37+00:00Added an answer on June 11, 2026 at 3:26 pm

    You should familiarize yourself with outerWidth(); I think it suits this situation quite well. When true is passed, it will take the outer width of a container, including the margin. Therefore, when you have an item of width 0, and take the outer width, it will be only the padding/margin/border you don’t want included in the width.

    Next, I played with your logic a bit. I took the total width of each bar instead of the inner width, then used the outer width to get the inner width from it. (That is, Container width / n -> Outer Width; Subtract padding -> Inner Width.)

    Last thing I want to note before sharing the updated fiddle is: Please, please, please, in the future, test your fiddle first. You had created bar and container variables, neither of which was defined. Nor had you used $(document).ready(...) or anything similar.

    First, I set your width to 0 (to get proper outer width). Then I calculated the width, as such:

    var barOuterWidth = Math.floor(containerWidth / n);
    var barInnerWidth = barOuterWidth - $(".bar").outerWidth(true);
    

    Lastly, I used 'width': barInnerWidth, to set the width.

    The result is in this jsFiddle. Notice there is a margin gap on the right; I’m sure you can find a way to alleviate this. (i == n - 1 or whatnot.)

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

Sidebar

Related Questions

I want to have 3 divs aligned inside a container div, something like this:
I have a div[class=container] and inside is div[class=item] like: <style type=text/css> .container{ height:50vh; width:
The idea: I have a container div with two divs inside of it, like
I have container did and there are many divs inside that div. In one
I have a container div listings_container that contains a variable number of divs listing
So I have 3 divs contained inside a containing div like such: <div id=contain>
I have a container layer with a width of 850px. Inside of that i
I have a resizable container div. Inside that div there's another resizable div. If
I have a container div that holds two internal divs; both should take 100%
I have a container div that is set to 90% width. I have a

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.