divs之间的空格 - display table-cell [英] space between divs - display table-cell

查看:137
本文介绍了divs之间的空格 - display table-cell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个div:

 < div style =display:table-cellid =div1 > 
content
< / div>

< div style =display:table-cellid =div2>
content
< / div>

有一种方法可以在这两个div :table-cell )?

解决方案

您可以使用 border-spacing 属性:



HTML

 < div class =table> ; 
< div class =row>
< div class =cell>单元格1< / div>
< div class =cell>单元格2< / div>
< / div>
< / div>

CSS:

  .table {
display:table;
border-collapse:separate;
border-spacing:10px;
}

.row {display:table-row; }

.cell {
display:table-cell;
padding:5px;
background-color:gold;
}

JSBin演示



任何其他选项?



不是真的。



为什么?
$ b


I have here two divs:

<div style="display:table-cell" id="div1">
    content
</div>

<div style="display:table-cell" id="div2">
    content
</div>

Is there a way to make space between these two divs (that have display:table-cell)?

解决方案

You can use border-spacing property:

HTML:

<div class="table">
    <div class="row">
        <div class="cell">Cell 1</div>
        <div class="cell">Cell 2</div>
    </div>
</div>

CSS:

.table {
  display: table;
  border-collapse: separate;
  border-spacing: 10px;
}

.row { display:table-row; }

.cell {
  display:table-cell;
  padding:5px;
  background-color: gold;
}

JSBin Demo

Any other option?

Well, not really.

Why?

  • margin property is not applicable to display: table-cell elements.
  • padding property doesn't create space between edges of the cells.
  • float property destroys the expected behavior of table-cell elements which are able to be as tall as their parent element.

这篇关于divs之间的空格 - display table-cell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆