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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:38:50+00:00 2026-06-14T12:38:50+00:00

I get an unwanted margin between block1 and block2 with display: inline-block style. See

  • 0

I get an unwanted margin between block1 and block2 with display: inline-block style. See this jsFiddle.

HTML

<div id="container">
    <div id="innercontainer">
        <div id="block1">
            block1
        </div>
        <div id="block2">
            block2
        </div>
    </div>
</div>

CSS

* {
    margin: 0px;
    padding: 0px;
}
#container {
    background-color: #f00;
    width: 100%;
    height: 200px;
}
#innercontainer {
    background-color: #0f0;
    width: 200px;
    height: 200px;
    margin: 0px auto;
}
#block1, #block2 {
    display: inline-block;
    background-color: #00f;
    height: 200px;
}

The margin disappears when I change the HTML to this:

<div id="container">
    <div id="innercontainer">
        <div id="block1">
            block1
        </div><div id="block2">
            block2
        </div>
    </div>
</div>

or this:

<div id="container">
    <div id="innercontainer">
        <div id="block1">
            block1
        </div><!--
     --><div id="block2">
            block2
        </div>
    </div>
</div>

While I prefer the latter, I still do wonder if anyone knows a solution so I can use the original HTML, but no whitespace shows up in innercontainer. Also note that I want to avoid setting float: left; on both block1 and block2 or making them floating by position: absolute|relative because that generates other problems in my layout. Any ideas?

EDIT

Ok, so I had more trouble with my layout. When I added an image to block1, the whole block moved down, very strange (see jsFiddle). I am now using float: left and will have to figure out how I can add a div that consumes the free-space on the right.

  • 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-14T12:38:51+00:00Added an answer on June 14, 2026 at 12:38 pm

    Update this part of css :

    #block1, #block2 {
        display: block;
        float: left;
        background-color: #00f;
        height: 200px;
    }
    

    When you are inline, spaces take space!

    EDIT :

    To be safe change this part of HTML

    <div id="container">
        <div id="innercontainer">
            <div id="block1">
                block1
            </div>
            <div id="block2">
                block2
            </div>
            <div style="clear: both"></div>
        </div>
    

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

Sidebar

Related Questions

Possible Duplicate: Unwanted margin in inline-block list items How to remove Invisible space from
When I create the following plot I get unwanted space between the plotting area
Im trying to do some horizontal layout of divs but get an unwanted margin
I can't manage to get rid of this unwanted horizontal scrolling space at the
Get class from div inside an li and add to the same li. The
I get this error while accessing a php script: W/System.err: Error reading from ./org/apache/harmony/awt/www/content/text/html.class
I get this error when I try to run my app: 2010-04-29 13:49:01.355 MyApp[56123:207]
The os.walk documentation ( http://docs.python.org/library/os.html ? highlight=os.walk#os.walk), says I can skip traversing unwanted directories
It looks like extra line breaks in the HTML code may add unwanted spaces
In a StringGrid, sometimes I get the unwanted menu below when I right-click. Is

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.