如何使用display:table-cell将div内的内容发送到容器的顶部?

时间:2015-04-23 14:28:24

标签: html css

我想将这两个div的内容放在顶部。

HTML

<div class="menu">
    <div></div>
</div>

<div class="content">
    <h1>SDFSDFSD SDFSD</h1>
    <h1>SDFSDFSD SDFSD</h1>
    <h1>SDFSDFSD SDFSD</h1>
</div>

CSS

menu {
    display: table-cell;
    background-color: yellow;
    width: 20%;
}

.menu > div {
    padding: 20px;
    background-color: red;
    vertical-align: top;
}

.content {
    display: table-cell;
    background-color: blue;
    width: 80%;
}

http://jsfiddle.net/99u4vm3g/

我尝试使用vertical-align:top和position:absolute和top:0但没有运气。

如何将这些内容发送到容器的顶部呢?

提前致谢!

2 个答案:

答案 0 :(得分:1)

您将table-cell添加到了错误的位置,它应该应用于def repo = 'example-sensu-rspec-tests' node { git url: 'https://github.com/bsnape/jenkins-workflow-example.git' common = load 'common.groovy' flow = load 'flow2.groovy' common.clone(repo) flow.unit() flow.acceptance() common.deploy('staging') } 元素。

已更新: http://jsfiddle.net/tfqmwko1/

答案 1 :(得分:1)

您需要将vertical-align放在table-cell元素

.menu {
    vertical-align: top;
}

.content {
    vertical-align: top;
}

http://jsfiddle.net/99u4vm3g/1/

您将看到文本仍然不在顶部,这是由于标题元素上的边距

此标题标题http://jsfiddle.net/99u4vm3g/2/

上没有边距