css - float 的 div 有一个边距,打破了流动

标签 css html css-float

我有两个 div:向左浮动和向右浮动。右侧 div 的边距打破了左侧 div,使其在页面上显示得比应有的位置低。 我希望两个 div 都触及顶部

HTML:

 <div class="right_div">
            This div is in the right place.
        </div>

    <div class="clear"> </div>

    <div class="left_div">

This div should be at the top</div>

CSS:

.right_div {

    float: right;
    margin-right:20px;
    margin-top: 20px;
    font-weight: 600;
    background-color:blue;
}

 .left_div{

    margin-left: 20px;
    margin: 0 0 0 20px;
    padding: 0;
    background-color: tomato;
    text-align: left;
    max-width: 10em;

 }

.clear {

    clear:both;
}

这是 JSFIDDLE:http://jsfiddle.net/eLSc8/

最佳答案

删除

<div class="clear"> </div>

试试这个

<div class="right_div">
            This div is in the right place.
        </div>

    <div class="left_div">

关于css - float 的 div 有一个边距,打破了流动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17365256/

相关文章:

html - 在两个并排的无序列表中排列列表元素

php 'include' 在 css 中给出错误

Jquery 返回带有 span 标签的 NaN

html - 汉堡包菜单未显示在我的网页上

javascript - jQuery Accordion 问题在这里

html - float 内联 block 和非 float block 之间的布局差异

css - Bootstrap 下拉菜单不支持悬停时的单个元素

html - 文字不会跟随背景图片

html - CSS flexbox |在移动设备中重新排序元素

css - 我可以将 DIV 始终显示在屏幕上,但不始终位于固定位置吗?