Where is this extra space between divs coming from?
Asked Answered
P

5

9

http://www.lethalmonk6.byethost24.com/index.html

If you inspect with firebug the spacing between the "project-link" divs, there are a few pixels of added margin between each div. I have the margin set to 20 px, and then these little bits gets added on. Where is it coming from?

Percolator answered 6/12, 2011 at 2:25 Comment(1)
possible duplicate of How to remove the space between inline-block elements?Lascar
S
23

You're using display:inline-block so the white space between the elements is what you are seeing there. You can either remove the white space between the divs or use float: left instead.

To elaborate... if you're using display: inline-block do this:

<div></div><div></div>

Instead of this:

<div></div>
<div></div> // White space is added because of the new line
Subsistence answered 6/12, 2011 at 2:29 Comment(2)
Is there a way I can remove the space?Percolator
Yes, by actually making the divs adjacent in your markup without any spaces or line breaks between them. See my added example...Subsistence
A
1

As Terminal Frost said, add float: left to the class, and remove display: inline-block. Additionally, add content: "." to the parent div container to fix the wrapping issue you'll have from doing that.

Aubreir answered 6/12, 2011 at 2:37 Comment(2)
content: "." doesnt really fix my wrapping issue, maybe I am not using it correctly?Percolator
You should put content: "." on the <div id="container"> element.Aubreir
E
1

As Lucifer Sam said, display:inline-block will show you space between element if there are one.

The slution given is good:

<div></div><div></div>

But for element with large content, i personnaly prefer this solution of not having the white space between display:inline-block elements. This is what i do:

   <div>
       large content
   </div><!-- No space
--><div>
       large content 2
   </div>
Escapee answered 1/3, 2014 at 16:36 Comment(0)
F
1

I wasn't quite happy with the provided solutions here and then I came across a fix that I actually was using to address this issue before, but forgot about it...

All you might need is to simply add font-size: 0; to the parent container (you can overwrite this rule for the children, so it shouldn't break your fonts).

So, here's a basic example:

<div class="font-zero">
    <div class="inline-block"></div>
    <div class="inline-block"></div>
    <div class="inline-block"></div>
</div>

<style>
    .font-zero { font-size: 0; }
    .inline-block { display: inline-block; }
</style>

With that example you don't have to worry about the markup in your code (personally, I think removing line breaks in the code to solve this issue is really ugly) and also you don't need to use floating, which might be not optimal for many reasons.

Since this page was the first Google result, I hope I'll get here next time I come across this issue and forget the easy fix... And maybe it would be useful for someone else too :)

Frontality answered 19/5, 2019 at 9:44 Comment(0)
M
0

I just stumbled here and my solution was to set overflow: hidden; on one of the elements that in my case was using filter: blur(5px);.

Malonis answered 23/8, 2023 at 19:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.