border-spacing

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

概述

border-spacing 属性指定相邻单元格边框之间的距离(只适用于 边框分离模式 )。相当于 HTML 中的 cellspacing 属性,但是第二个可选的值可以用来设置不同于水平间距的垂直间距。

border-spacing 值也适用于表格的外层边框上,即表格的边框和第一行的、第一列的、最后一行的、最后一列的单元格之间的间距是由表格相应的(水平的或垂直的)边框间距(border-spacing)和相应的(上,右,下或左)内边距之和。

该属性只适用于 border-collapse 值是 separate 的时候。

初始值0
适用元素tableinline-table 元素
是否是继承属性
计算值两个绝对长度
动画类型离散值

语法

/* <length> */
border-spacing: 2px;

/* horizontal <length> | vertical <length> */
border-spacing: 1cm 2em;

/* Global values */
border-spacing: inherit;
border-spacing: initial;
border-spacing: unset;

length

描述单元格之间的水平和垂直距离的一个 <length> 值。它只在单值语法下使用。

horizontal

描述相邻两列的单元格之间的水平距离的一个 <length> 值。它只在双值语法下使用。

vertical

描述相邻两行的单元格之间的垂直距离的一个 <length> 值。它只在双值语法下使用。

inherit

一个表示父元素的 border-spacing 的计算值的关键字,其父元素必须应用了 border-spacing

正式语法

border-spacing = 
<length>{1,2}

示例

查看在线演示

css
table {
  border-spacing: 10px 5px;
}

规范

Specification
Cascading Style Sheets Level 2
# separated-borders

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
border-spacing

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support