css - 为什么 margin 不应用而没有溢出 :auto

标签 css css-float

我正在尝试创建一个标签和文本彼此相邻的 View 页面。现在不提 overflow auto 就不会计算利润率。为什么??

这是我的 CSS 和 HTML。

.dl-horizontal {
    margin-bottom: 20px;
    /*overflow:auto*/
}

.dl-horizontal dt {
    clear: left;
    float: left;
    font-weight: bold;
    line-height: 25px;
    width: 160px;
}

.dl-horizontal dd {
    content: " ";
    display: table;
    line-height: 25px;
}


.action-wrap{
    clear: both;
    margin-top: 20px;
}
<dl class="dl-horizontal">
    <dt>Name:</dt>          <dd>My Name</dd>
    <dt>Description:</dt>   <dd>Lorem ipsuem</dd>
    <dt>Group:</dt>         <dd></dd>
</dl>
<div class="action-wrap ng-scope">
     <button class="button cancel" >Cancel</button>
</div>

我个人多次遇到这个问题,我的快速修复是 overflow:auto。想知道是否可以使用它,还是我做错了什么。

最佳答案

更新:我找到了更好的方法,忘了我下面说的吧。只需添加显示:表格;到 .dl-水平选择器。现在每个红色边框(出于视觉目的)都相同。

看来,如果dd标签中没有任何内容,它不会将行向下推。顺便说一下, padding-bottom: 20px 可以,但如果你不想这样做,你可能必须在 dd 字段中放置一个(不间断的空格)。这似乎也有效。 CSS 有很多怪癖:)

.dl-horizontal {
    margin-bottom: 20px;
    display: table;
border-bottom: 1px solid red;
}

.dl-horizontal dt {
    clear: left;
    float: left;
    font-weight: bold;
    line-height: 25px;
    width: 160px;
}

.dl-horizontal dd {
    content: " ";
    display: table;
    line-height: 25px;
}


.action-wrap{
    clear: both;
    margin-top: 20px;
}
<dl class="dl-horizontal">
    <dt>Name:</dt>          <dd>My Name</dd>
    <dt>Description:</dt>   <dd>Lorem ipsuem</dd>
    <dt>Group:</dt>         <dd></dd>
</dl>
<div class="action-wrap ng-scope">
     <button class="button cancel" >Cancel</button>
</div>
<dl class="dl-horizontal">
    <dt>Name:</dt>          <dd>My Name</dd>
    <dt>Description:</dt>   <dd>Lorem ipsuem</dd>
    <dt>Group:</dt>         <dd>&nbsp;</dd>
</dl>
<div class="action-wrap ng-scope">
     <button class="button cancel" >Cancel</button>
</div>

关于css - 为什么 margin 不应用而没有溢出 :auto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28229495/

相关文章:

jquery - 以大型网站为中心的视口(viewport)

css - 指定 flexbox cross size grow 值

html - 之前和之后的 Css 形状

CSS 左对齐 float 但受右边距限制

css - 为内容移出容器的菜单设置垂直背景

jquery - 如何通过jQuery在PC和移动设备上加载CSS?

css - 文本溢出隐藏中断 float

css - 如何在父容器没有宽度的情况下居中对齐 float div?

html - CSS float 定位

html - 使用 CSS 制作动画