小编Mde*_*mez的帖子

具有边距的多个div用于填充父宽度

我试图让多个div占用父div的整个宽度.为了做到这一点,我使用display:tabledisplay:table-cell.这种方法的问题是我不能为子div添加边距以便在它们之间留出一些空间.现在他们都堆叠在一起,看起来不太好.

有什么建议?

这是代码:

HTML

.parent {
      text-align:center;
      margin:0px;
      width:500px;
      padding:0px;
      background:blue;
      display:table;
      box-sizing:border-box;
      -moz-box-sizing:border-box;
      -webkit-box-sizing:border-box;
      list-style-type:none;
    }
    
.child{
      padding:15px;
      background:#f00;
      display:table-cell;
      list-style-type:none;
    }
    
.child:nth-child(2n) {background:green;}
Run Code Online (Sandbox Code Playgroud)

CSS

<div class="parent">
<div class="child">sometext</div>
<div class="child">somemoretext</div>
<div class="child">sometext</div>
<div class="child">sometext</div>
</div>
Run Code Online (Sandbox Code Playgroud)

这是一个实时版本:http://codepen.io/mariomez/pen/MaXjqW

html css width css-tables

3
推荐指数
1
解决办法
1218
查看次数

标签 统计

css ×1

css-tables ×1

html ×1

width ×1