-1

I'm trying to make some buttons with equal spacing between each other (both vertically and hortizontally), but the problem I've encountered is that the horizontal spacing is always bigger than I want it to be. This is not a huge problem for my project, but I'm still curious as to why chrome adds this extra space.

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <button class="help-me-stack-overflow">button 1</button>
        <button class="help-me-stack-overflow">button 2</button><br>
        <button class="help-me-stack-overflow">button 3</button>
        <button class="help-me-stack-overflow">button 4</button>
        <style>
            .help-me-stack-overflow {
                width: 100px;
                height: 50px;
                margin: 0px;
            }
        </style>
    </body>
</html>

This is how it looks when rendered in chrome:

the spacing between the buttons is not 0px!

Any help is greatly appreciated!

Natrium
  • 75
  • 6

1 Answers1

1

Because there is actually a space in your code. Two ways to fix this.

  1. Remove the whitespace in your actual code:
<button class="help-me-stack-overflow">button 1</button>
<button class="help-me-stack-overflow">button 2</button>

becomes

<button class="help-me-stack-overflow">button 1</button><button class="help-me-stack-overflow">button 2</button>

Or 2. set font-size:0 on your container.

Liftoff
  • 24,717
  • 13
  • 66
  • 119