html - 奇怪{显示:table} behavior

标签 html css css-tables

我想不通这个。 当 display:tabledisplay:table-cell 一起使用时,在 cell1 或 cell2 中放置一个 img 标签将强制显示内容(“This is a test”内容例如),在另一个单元格中放置在图像下方。它是否正确?它在所有浏览器上都这样做,所以我认为这是正确的,但为什么呢?

<html>
<head>
    <title></title>
    <style type="text/css">
        html,
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
        div {
            border: 2px solid #000;
            width: 100%;
            height: 100%;
        }
        .table {
            display: table;
            border-collapse: collapse;
        }
        .row {
            display: table-row;
        }
        .cell {
            display: table-cell;
            width: 50%;
        }
    </style>
</head>
<body>
    <div class="table">
        <div class="row">
            <div id="cell1" class="cell">
                <h1>This is a test</h1>
            </div>
            <div id="cell2" class="cell">
                <img src="" />
            </div>
        </div>
    </div>
</body>
</html>

最佳答案

嗯。 vertical-align: top 在表格单元格中。

工作示例:at jsFiddle

关于html - 奇怪{显示:table} behavior,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5518709/

相关文章:

css 中的 PHP 变量不更新/刷新

html - 固定位置元素在向下滚动到新页面时改变颜色

css - Clearfix 自动删除边距 0?

java - Jsoup 匹配任何具有命名空间的元素

html - 不同div的水平对齐

html - 在 html 中嵌入 mp3

html - 将 Bootstrap 样式应用于 Struts 1.x html 标记

wordpress - 复选框不显示为已选中

html - 带圆 Angular 的可滚动表格

css - 添加边距以显示 : table-cell child element