1

I have the following code: http://jsfiddle.net/yxxhj33x/

As you can see, I have the .links element followed by a input[type='text'] element. Unfortunately, there is a margin above the input, which won't go away when I add:

.links {
  display: inline-block;
  border: 1px solid black;
  width: 100%;
  font-size: 0;
  white-space: nowrap;
  overflow-x: auto;
}

.links a {
  background: #FFF;
  display: inline-block;
  min-width: 100px;
  width: 25%;
  text-align: center;
  border-right: 1px black solid;
  height: 50px;
  font-size: 16px;
}
<div class='links'>
    <a href='#'>Blah</a>
    <a href='#'>Blah</a>
    <a href='#'>Blah</a>
    <a href='#'>Blah</a>
</div>
<input type='text'>
input[type='text'] {
  margin: 0;
}

How do I fix this?

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
infinity
  • 719
  • 2
  • 11
  • 23

1 Answers1

2

In addition to removing the space between inline elements, you need to change the value of the vertical-align property on the .links element. It's worth pointing out that the default value is baseline. When it is set to baseline on an inline element, there is a reserved space for letters such as f, j, p and q (these letters hang lower (or are taller) than other letters, thus the reserved space).

Updated Example

.links {
    display: inline-block;
    border: 1px solid black;
    width: 100%;
    font-size: 0;
    white-space: nowrap;
    overflow-x: auto;
    vertical-align: bottom;   /* Added.. */
}
.links a {
    box-sizing: border-box;   /* Added.. */
}

It's also worth pointing out that the widths of the a elements didn't add up to 100% (since the border isn't included in the element's width calculations). In order to remove the scollbar, add box-sizing: border-box to the anchor elements.


As a side note, since you're setting a width of 100% on the parent .links element, it really doesn't need to have a display of inline-block. You should make it a block level element (by omitting display: inline-block, since it's already a div and block level by default). In doing so, you actually don't need to add vertical-align: bottom anymore, since block level elements don't respect this property.

Example Here

.links {
    border: 1px solid black;
    font-size: 0;
    white-space: nowrap;
    overflow-x: auto;
}
.links a {
    box-sizing: border-box;
}
Community
  • 1
  • 1
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304