css - DIV 不使用 CSS float 对齐左上角和右上角

标签 css html

抱歉,我对 HTML 和 CSS 有点陌生,但我已经尝试了一切,但我似乎无法让它工作。我有一个顶部 DIV 和一个底部 DIV。顶部 DIV 包含另外两个需要左右对齐的 DIV。

<!DOCTYPE html>
<html>
<body>
    <div>
        <div style="border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(187, 187, 187);">
            <div style="font-size: 30px; float: left;">Top Left</div>
            <div style="font-size: 30px; float: right;">Top Right</div>
        </div>
        <div >blah blah blah blah blah blah blah blah blah blah blah
        blah blah blah blah blah blah blah blah blah blah blah blah
            blah blah blah blah blah blah blah blah blah blah blah blah
            blah blah blah
        </div>
    </div>
</body>
</html>

我想看到类似的东西:

Top Left                          Top Right
-------------------------------------------

blah blah blah blah blah blah blah 

但是我得到了

----------------------------
Top Left blah blah Top Right

似乎顶部 DIV 的高度设置为零。为什么我不知道。我想如果你把东西放在 DIV 中它应该会自动拉伸(stretch)?

我的实际代码是:

<div style="border-bottom: 1px solid rgb(187, 187, 187); overflow: auto; clear: both; padding: 15px;">
    <div style="font-size: 30px;">Bearbeiten</div>
    <div style="font-size: 30px; width: 50px;">X</div>
</div>
<div style="position: absolute; bottom: 10px;"><input style="font-size: 15px; height: 30px; width: 130px;"
                                                      value="Cancel" class="OverlayButton" id="Overlay.CancelButton"
                                                      type="button"><input
        style="font-size: 15px; height: 30px; width: 130px;" value="Save" class="OverlayButton" type="button"><input
        style="font-size: 15px; height: 30px; width: 130px;" value="Delete" class="OverlayButton" type="button"></div>

最佳答案

overflow: hidden 放在包含两个 float 的 div 上。

http://jsfiddle.net/SntpD/

您也可以使用 CSS :after,但它有点复杂。

.container:after {
    clear: both;
    display: block;
    content: "";
    height: 0;
}

http://jsfiddle.net/SntpD/1/

关于css - DIV 不使用 CSS float 对齐左上角和右上角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15684533/

相关文章:

css - 替换变量并使用 sass 确定结果范围

javascript - 如何使用热键打开多个链接?

javascript - 如何在 Angular 6 中设置背景图像图像路径

jquery - 显示 Facebook、Instagram 和其他社交网站等更新

html - 将 2 个表格的单元格列对齐在一起

css - 如何将列表 ul 设置为正方形

php - 表单表 Bootstrap 中的 PHP 发布方法

php - word-wrap 属性似乎在 CSS 中不起作用

php - 我想使用 php 更新数据库(mysql)中单选按钮的值

html - 视频结束后恢复为海报图像