html - 为什么将图像添加到显示为 : table-cell add a whack-load of padding? 的 div

标签 html css

我该如何去掉填充?

检查一下(jfiddle version):

CSS:

.table
{
    display: table;
    height: 250px;

    border-color: black;
    width: 500px;
    padding: 0px;
}

.cell
{
    display: table-cell;
    height: 250px;
    width: 50%;
    padding 0px;
    border-color: blue;
    border-style: solid;
}

.cell img
{
    width: 250px;
    height: 250px;
    border-color: red;
    border-style: solid;
}

HTML:

<div class="table">
<div class="cell">
    <img src="">
</div>
<div class="cell">
    Caption
</div>
</div>

如果删除 img 元素,左侧单元格中的填充将消失。奇怪的是,我将所有内容的填充设置为 0。

最佳答案

事实并非如此。您看到的是默认值 vertical-align作用中的属性,即 baseline

如果将单元格的垂直对齐方式更改为 top(或 middlebottom,具体取决于文本的位置),您将得到你想要的。

jsFiddle example

关于html - 为什么将图像添加到显示为 : table-cell add a whack-load of padding? 的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23572948/

相关文章:

html - 列表项中的 Bootstrap 侧边栏链接占据了整个按钮

javascript - 如何使用 Angular JS 创建可复制的 html 代码

javascript - Angular 指令 DOM 操作行为

css - 如何让媒体查询识别横向?

javascript - jquery mobile Pageshow - 删除以前的数据

html - 在物化中将 Col/Card 面板居中

css - Shiny 的 selectInput 旁边的标签

html - 如何在 CSS 中制作没有图像的自定义选择选项菜单样式?

CSS 兄弟选择器未触发

css - 在 SVG 标签之外添加 SVG Def