javascript “显示:表格单元格”之间的填充

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9570679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:05:06  来源:igfitidea点击:

Padding Between "display:table-cell"

javascriptcsshtml

提问by user1152440

Is there a way to place padding or a transparent border around the "cells" when one does display:table-cell? I would like the background to show up through this space, so I can't just set the border to white, and border-color:transparentdoesn't work for me for some reason. I've checked w3schools and similar sites but I haven't been able to find this particular trait.

有没有办法在“单元格”周围放置填充或透明边框display:table-cell?我希望背景通过这个空间显示出来,所以我不能将边框设置为白色,并且border-color:transparent由于某种原因对我不起作用。我已经检查过 w3schools 和类似的网站,但我一直无法找到这个特殊的特征。

From user Praveen Vijayan: http://jsfiddle.net/geymU/

来自用户Praveen Vijayanhttp: //jsfiddle.net/geymU/

回答by Starx

Use border-spacing: 10pxon the parent container.

使用border-spacing: 10px父容器上。

In your case

在你的情况下

#nav ul{
    display:table;
    width:100%;
    border-spacing: 10px;
}

You can also give top/bottom and left/right separately like border-spacing: 10px 20px;

你也可以分别给上/下和左/右,比如 border-spacing: 10px 20px;

回答by Quentin

The space between cells is controlled by the border-spacingand border-collapseproperties in the table.

单元格之间的空间由表中的border-spacingborder-collapse属性控制。

#nav ul {
    display: table;
    width: 100%;
    background: yellow;
    border-collapse: separate;
    border-spacing: 12px 6px;
}