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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:20:38+00:00 2026-05-20T01:20:38+00:00

I have the following HTML: <ul> <li> <div>first</div> </li> <li> <div>first</div> </li> <li> <div>first</div>

  • 0

I have the following HTML:

    <ul>
        <li>
        <div>first</div>
        </li>
        <li>
        <div>first</div>
        </li>
        <li>
        <div>first</div>
        </li>
        <li>
        <div>first</div>
        </li>
    </ul>

and the following css rules:

        ul {
            padding: 0;
            border: solid 1px #000;
        }
        li {
            display:inline-block;
            padding: 10px;
            width: 114px;
            border: solid 1px #f00;
            margin: 0;
        }

        li div {
            background-color: #000;
            width: 114px;
            height: 114px;
            color: #fff;
            font-size: 18px;
        }

For some strange reason, the list items appear with a margin around them in both Firefox and Chrome. Looking at firebug, the list items do not have any margin at all, but there seems to be a void space between them.

If I later on add more list items via javascript using

$('<li><div>added via js</div></li>').appendTo($('ul'));

the “margin” doesn’t appear around the new elements:

Unwanted margins

Any idea of what the hell’s happening here?

  • 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-20T01:20:38+00:00Added an answer on May 20, 2026 at 1:20 am

    This is caused by the display: inline-block;

    li {
        display: inline-block;
        padding: 10px;
        width: 114px;
        border: solid 1px #f00;
        margin: 0;
    }
    

    Change it to float: left;.

    I thought it was the padding but took a closer look and turns out it was the display 🙂

    Example here.


    After further research I have discovered that inline-block is a whitespace dependent method and renders a 4px margin to the right of each element.

    To avoid this you could run all your lis together in one line, or block the end tags and begin tags together like this:

    <ul>
            <li>
                <div>first</div>
            </li><li>
                <div>first</div>
            </li><li>
                <div>first</div>
            </li><li>
                <div>first</div>
            </li>
    </ul>
    

    Example here.

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

Sidebar

Related Questions

I have the following: CSS #pageBody { height: 500px; padding:0; margin:0; /*border: 1px solid
I have the following HTML and I need to get the first div parent
I have the following html <div id=to-sort> <div class=block data-id=1>aaaaa</div> <div class=block data-id=2>bbbbb</div> <div
i have html code that looks like the following: String html = <html><head><style type=\text/css\></style></head><body><div
I have following HTML code: <div id=wrapper> <div class=page id=first> Test<br/> Test<br/> Test<br/> Test<br/>
I have the following HTML and CSS: <div id=topdevelopments class=colnm colw6 clearfix> <a href=homes-for-sale/development/beaufort-park-6/
I have the following HTML: <div id=mydiv> </div> I would like to load content
I have the following HTML <div id=testID class=test1> <img id=testID2 class=test2 alt= src=some-image.gif />
I have the following html: <div id=container> <ul> <li>element 1</li> <li>element 2</li> </ul> </div>
I have the following HTML: <div style=30px;> <table width=100%;> <tr> <td> <SELECT name=guidelinks> <OPTION

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.