Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS inline-block causing extra space between 2 vertical divs [duplicate]

Tags:

css

I have several div (class="badge") to display in the vertical. Not sure why I got extra space between 2 div in FF and IE (Chrome works fine).

I need them to display either no space or equal space in all browsers.

http://jsfiddle.net/2hxak/1/

HTML:

<div class="stat-badges">
    <div class="badge">
        <div class="stat-num">123456</div>
    </div>
    <div class="badge">
        <div class="stat-num">0</div>
    </div>
</div>

CSS:

.stat-badges {
  text-align: center;
  width: 55px;
}
.badge {
  display: inline-block;
  padding: 2px 4px;
  color: #ffffff;
  vertical-align: baseline;
  white-space: nowrap;
  background-color: #999999;
}
.badge .stat-num {
  max-width: 30px;
  min-width: 20px;
  padding: 3px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

The space will disappear if I remove overflow: hidden;. I keep overflow: hidden with ellipse to crop long text.

like image 303
anvoz Avatar asked Jul 08 '13 14:07

anvoz


2 Answers

Change vertical-align: baseline; to vertical-align: top; in your badge class rule.

jsFiddle example

like image 107
j08691 Avatar answered Sep 22 '22 17:09

j08691


display: inline-block; is messing this up. Use float: left; instead (possibly with clear: left; to make sure every badge is on a new line). (jsFiddle)

like image 28
Sumurai8 Avatar answered Sep 26 '22 17:09

Sumurai8