【问题标题】:How to vertically top align div inside of div?如何在div内垂直顶部对齐div?
【发布时间】:2014-10-29 21:59:29
【问题描述】:

我正在尝试在 div 中顶部对齐 div,但没有成功。 http://jsfiddle.net/jhbs31xv/

<table style="border: 1px solid red; width: 100%">
    <tr>
        <td>
            <div style="display: table-cell; width: 200px; height: 500px; overflow-y: auto;">
                <div id="housingTree" class="demo" style="height: 100px;">
                </div>
            </div>
        </td>
        <td style="width: 100%; height: 100%; border: 1px solid blue;">
            <div style="height: 100%; width: 100%;">

                <div id="infoPane" style="width:100%;margin-left:10px; border: 1px solid green;vertical-align:top; ">
                    How To Top Align Me?

                </div>

            </div>
        </td>
    </tr>
</table>

【问题讨论】:

    标签: html css


    【解决方案1】:

    像这样:

    <td style="width: 100%; height: 100%; border: 1px solid blue;" valign="top">
            <div style="height: 100%; width: 100%;">
    
                <div id="infoPane" style="width:100%;margin-left:10px; border: 1px solid green; ">
                    How To Top Align Me?
    
                </div>
    
            </div>
        </td>
    

    将 valign="top" 添加到包含的 .

    而且,正如 Goos van den Bekerom 所提到的,你不应该在 td 中使用 div....

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-25
      • 2014-07-17
      • 2012-09-11
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多