Why does this inline block element create extra width?

This is a continuation of this question: Auto-update text below image only css

Why do the inline block dividers in this code produce extra width on the right side of the elements?

.item {
  display: inline-block;
  background-color: red;
}

.image-container {
  background-color: blue;
  display: table;
  width: 1%;
}

img {
  height: 120px;
}

.text-wrapper {
  overflow: hidden;
}
<div class="item">
  <div class='image-container'>
    <img src='http://i.imgur.com/nV2qBpe.jpg' class="image">
    <div class='text-wrapper'>
      <p class='text'>Some text that may need to wrap into multiple lines</p>
    </div>
  </div>
</div>

<div class="item">
  <div class='image-container'>
    <img src='http://i.imgur.com/nV2qBpe.jpg' class="image">
    <div class='text-wrapper'>
      <p class='text'>Some text that may need to wrap into multiple lines</p>
    </div>
  </div>
</div>

<div class="item">
  <div class='image-container'>
    <img src='http://i.imgur.com/nV2qBpe.jpg' class="image">
    <div class='text-wrapper'>
      <p class='text'>Some text that may need to wrap into multiple lines</p>
    </div>
  </div>
</div>

<div class="item">
  <div class='image-container'>
    <img src='http://i.imgur.com/nV2qBpe.jpg' class="image">
    <div class='text-wrapper'>
      <p class='text'>Some text that may need to wrap into multiple lines</p>
    </div>
  </div>
</div>
Run codeHide result

Edit: this is NOT a problem with spaces, see this jsfiddle without any spaces and note that the div still takes up a lot of extra space (red area): https://jsfiddle.net/2Lzo9vfc/332/

Edit2: : N , " ", , . , , , , (, , ).

+4
3

, , . . , :

.item {
  display: inline-block;
  background-color: blue;
  width: 120px;
}

.image {
  display: block;
  height: 120px;
}
<div class="item">
  <img src='http://i.imgur.com/nV2qBpe.jpg' class="image">
  <p class='text'>Some text that may need to wrap into multiple lines</p>
</div>

<div class="item">
  <img src='http://i.imgur.com/nV2qBpe.jpg' class="image">
  <p class='text'>Some text that may need to wrap into multiple lines</p>
</div>

<div class="item">
  <img src='http://i.imgur.com/nV2qBpe.jpg' class="image">
  <p class='text'>Some text that may need to wrap into multiple lines</p>
</div>

<div class="item">
  <img src='http://i.imgur.com/nV2qBpe.jpg' class="image">
  <p class='text'>Some text that may need to wrap into multiple lines</p>
</div>
Hide result

, , , .

+1

@Brandon Gano . display: table-caption; .text-wrapper.

CSS, jsfiddle:

.text-wrapper {
  overflow: hidden;
  display: table-caption;
  caption-side: bottom;
  height: 60px;             /* You may have to modify the height */
  background-color: blue;
}

jsfiddle.

+1

inline-block. , . :.

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

, .

-3

Source: https://habr.com/ru/post/1619248/


All Articles