html - 删除垂直 div 之间的空间

标签 html css image

<div class="flex-33">      
      <div class="menu-container">
        <img class="menu-image" src="img/bocadillobody.png" alt="Sandwitch">
        <div class="menu-description">
         <h4>Sandwitch</h4>
         <p>Powder marshmallow marshmallow brownie carrot cake candy bonbon. Sweet sugar plum gummies caramels tart carrot cake tiramisu cheesecake. Cheesecake biscuit jelly beans. Jelly-o icing chocolate macaroon.   </p>
      </div>
    </div>          
</div>

有人可以帮我消除两个 div img.menu-description 之间的空白吗?

我估计在过去的 3 小时里我尝试了所有解释的内容 here , 但只有部分运气,空白消失,但在更改浏览器 width 时重新出现。

最佳答案

因为 img 是内联级元素,将 img 设置为 display:block 成为 block 级元素,因此空格被删除。

.flex-33 div {
  border: red solid 1px
}
img {
  display: block
}
<div class="flex-33">
  <div class="menu-container">
    <img class="menu-image" src="//lorempixel.com/100/100" alt="Sandwitch">
    <div class="menu-description">
      <h4>Sandwitch</h4>
      <p>Powder marshmallow marshmallow brownie carrot cake candy bonbon. Sweet sugar plum gummies caramels tart carrot cake tiramisu cheesecake. Cheesecake biscuit jelly beans. Jelly-o icing chocolate macaroon.</p>
    </div>
  </div>
</div>

或者你可以在 img 上设置 vertical-align:bottom 因为默认情况下 imgvertical-align:baseline

.flex-33 div {
  border: red solid 1px
}
img {
  vertical-align:bottom
}
<div class="flex-33">
  <div class="menu-container">
    <img class="menu-image" src="//lorempixel.com/100/100" alt="Sandwitch">
    <div class="menu-description">
      <h4>Sandwitch</h4>
      <p>Powder marshmallow marshmallow brownie carrot cake candy bonbon. Sweet sugar plum gummies caramels tart carrot cake tiramisu cheesecake. Cheesecake biscuit jelly beans. Jelly-o icing chocolate macaroon.</p>
    </div>
  </div>
</div>

关于html - 删除垂直 div 之间的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36781572/

相关文章:

javascript - 如何为图像设置计时器以在 javascript 或 html 中显示?

javascript - 将 img src 插入输入 onClick

css - 将自定义元素解析为 shady dom 树后,不会应用自定义 css 属性

CSS停止图像下的文字换行

php - 我需要为此页面添加分页,因为我正在从 db 动态获取一组元素

html - 更改 bootstrap css 文件,但不工作

javascript - 如何在屏幕上显示弹出中心

java - 在 Java FX 中定义图像的相对路径

html - 微博 : how to make div wrap around photo?

mysql - 在 mysql 的内容中搜索和替换图像尺寸?