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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:42:31+00:00 2026-05-22T17:42:31+00:00

When I try to put 5 inline-block divs of 20% width with 1px borders,

  • 0

When I try to put 5 inline-block divs of 20% width with 1px borders, inside a containing div, also with a 1px border, they wrap on to the next line.

They do fit if I get rid of all the borders.

I understand that this is because the divs take up 100% of the containing divs area, including its padding and border area, meaning that they don’t fit within the borders, so it has to wrap.

My question is how to modify this so that I can make them fit exactly. Surely this is a common problem?

<html>
    <head>
        <title> Test </title>
        <style type=text/css>

            div
            {
                margin: 0;
                padding: 0;
            }
            #navBar
            {
                border: 1px solid black;
                margin-left: auto;
                margin-right: auto;
                margin-top: 10px;
                width: 50%;
            }
            .navBtn
            {
                border: 1px solid black;
                display: inline-block;
                text-align: center;
            }
        </style>
    </head>
    <body>
        <div id="navBar">
            <div class="navBtn" style="width:20%">Text</div><div class="navBtn" style="width:20%">Text</div><div class="navBtn" style="width:20%">Text</div><div class="navBtn" style="width:20%">Text</div><div class="navBtn" style="width:20%">Text</div>
        </div>
    </body>
</html>

As a side note, it’s crazy that if I put the 5 divs on their own lines, they get rendered with space between them, hence why they’re all on one line. In my real code the divs are generated with php, so it’s not long.

  • 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-22T17:42:31+00:00Added an answer on May 22, 2026 at 5:42 pm

    margin:0 -1px 0 -1px gives you an easy place to start.

    Would also recommend using float:left for this since display:inline-block is buggy in some browsers.

    To get your container <div> to expand vertically to fit content, just have an element with clear:both after your floated ones.

    All can be seen here: http://jsfiddle.net/steve/qEJaA/

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

Sidebar

Related Questions

I try to put a border on a table for printview and in pdf
I try to put slide bar inside jquery fancybox popup but some events like
I try to put a regular button inside an image in android XML. How
I try to put this html: <ol> <li><span><img src=http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/102.gif width=10ex height=1em/></span>Something</li> <li><span><img src=http://www.smallbusinessfriends.com/wp-content/uploads/2011/05/cms.jpg width=10ex
i try to put a lock to a static string object to access to
When I try to put a value into a DATE field which is invalid,
I’m using C# and WinForms to try and put just the date from a
I am getting raw aac data from web stream and try to put it
I have this code for update: public Boolean update() { try { data.put(ContactsContract.Groups.SHOULD_SYNC, true);
I have a UITableViewCell and it is UITableViewCellStyleDefault . When I try to put

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.