7

When I add

overflow:hidden

to any of the buttons on my page, it creates 13px of margin at the bottom of the button. When I remove the above CSS, the margin disappears, however some content inside the button overflows.

How can I remove the margin at the bottom, while keeping the

overflow:hidden

CSS style?

WITH overflow:hidden hidden

WITHOUT overflow:hidden without

, however, the Facebook logo overflows into the next button (it is a custom font)

CURRENT BUTTON CSS:

.btn {
    background-color: #FF6347;
    border: 1px solid #CC4F39;
    color: #FFFFFF;
    text-decoration: none;
    padding: 7px 15px;
    cursor: pointer;
    font-size: 1em;
    text-shadow: 0 1px 2px #000000;
    display: inline-block;
    overflow: hidden;
}

CURRENT BUTTON HTML:

<a class="btn btn-fb btn-xl" id="login_fb"><span class="icon-socialfacebookvariant"></span>Log In</a>

CURRENT FACEBOOK LOGO CSS:

[class^="icon-"], [class*=" icon-"] {
    overflow:hidden;
}

[class^="icon-"]:before, [class*=" icon-"]:before {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size:2em;
    line-height:0;
    font-family: 'icomoon';
    position:relative;
    top:-1px;
    speak: none;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    vertical-align:middle;
}

// Facebook logo from a font
.icon-socialfacebookvariant:before {
    content: "\e9e3";
}
zuc0001
  • 924
  • 4
  • 12
  • 27

2 Answers2

6

Thanks Jaunt for the help.

Although your idea is the most logical, it's not very nice when editing!

Luckily I happened to come across a simple fix to my problem!

All I had to do was add vertical-align:top to my button CSS, and wham! it works!

Thanks for your help :)

zuc0001
  • 924
  • 4
  • 12
  • 27
  • 1
    Sometimes my way is the only way, I'm actually really glad there's another fix because it's ugly as all hell. Well done for finding it! :) – jaunt Jul 25 '15 at 12:40
  • Thanks guys. Yeah I spent like 2 hours trying to fix this thing, then I came across that simple code. – zuc0001 Jul 25 '15 at 12:43
  • 1
    If this fixes the problem, the problem was probably the same as [Why does my image have space underneath?](http://stackoverflow.com/q/17905827/1529630) – Oriol Jul 25 '15 at 12:58
  • 2
    `display:inline-block` by default is set to `vertical-align:baseline` therefore you setting `vertical-align:top` fix that ;) – dippas Jul 25 '15 at 13:21
  • yeah that seems right. I'll remember this trick for future reference – zuc0001 Jul 25 '15 at 13:24
4

It's because you have white-spacing between the HTML elements. This snippet is with the white-spacing:

.btn {
    background-color: #FF6347;
    border: 1px solid #CC4F39;
    color: #FFFFFF;
    text-decoration: none;
    padding: 7px 15px;
    cursor: pointer;
    font-size: 1em;
    text-shadow: 0 1px 2px #000000;
    display: inline-block;
    overflow: hidden;
}
<div class="btn"></div>
<div class="btn"></div>
<div class="btn"></div>
<div class="btn"></div>
<div class="btn"></div>

And this one is without:

.btn {
    background-color: #FF6347;
    border: 1px solid #CC4F39;
    color: #FFFFFF;
    text-decoration: none;
    padding: 7px 15px;
    cursor: pointer;
    font-size: 1em;
    text-shadow: 0 1px 2px #000000;
    display: inline-block;
    overflow: hidden;
}
<div class="btn"></div><div class="btn"></div><div class="btn"></div><div class="btn"></div><div class="btn"></div>

There is a notable difference and I believe this is where your mysterious margin is coming from.

jaunt
  • 4,978
  • 4
  • 33
  • 54
  • 1
    White space in the HTML source produces space between inline-level boxes at the same line box, but not between different line boxes. – Oriol Jul 25 '15 at 13:00