- Notifications
You must be signed in to change notification settings - Fork 22.7k
/
Copy pathindex.md
160 lines (121 loc) · 3.62 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
---
title: border-spacing
slug: Web/CSS/border-spacing
page-type: css-property
browser-compat: css.properties.border-spacing
---
{{CSSRef}}
The **`border-spacing`**[CSS](/en-US/docs/Web/CSS) property sets the distance between the borders of adjacent cells in a {{htmlelement("table")}}. This property applies only when {{cssxref("border-collapse")}} is `separate`.
{{InteractiveExample("CSS Demo: border-spacing")}}
```css interactive-example-choice
border-spacing: 0;
```
```css interactive-example-choice
border-spacing: 5px;
```
```css interactive-example-choice
border-spacing: 5px 1rem;
```
```htmlinteractive-example
<section class="default-example" id="default-example">
<table class="transition-all" id="example-element">
<tr>
<td>Cell 1.1</td>
<td>Cell 1.2</td>
</tr>
<tr>
<td>Cell 2.1</td>
<td>Cell 2.2</td>
</tr>
<tr>
<td>Cell 3.1</td>
<td>Cell 3.2</td>
</tr>
</table>
</section>
```
```css interactive-example
table {
width: 15rem;
table-layout: fixed;
}
td {
border: 5pxsolid;
border-color: crimsondodgerblue;
padding: 0.75rem;
}
```
The `border-spacing` value is also used along the outside edge of the table, where the distance between the table's border and the cells in the first/last column or row is the sum of the relevant (horizontal or vertical) `border-spacing` and the relevant (top, right, bottom, or left) {{cssxref("padding")}} on the table.
> [!NOTE]
> The `border-spacing` property is equivalent to the deprecated `cellspacing` attribute of the `<table>` element, except that `border-spacing` has an optional second value that can be used to set different horizontal and vertical spacing.
## Syntax
```css
/* <length> */
border-spacing: 2px;
/* horizontal <length> | vertical <length> */
border-spacing: 1cm 2em;
/* Global values */
border-spacing: inherit;
border-spacing: initial;
border-spacing: revert;
border-spacing: revert-layer;
border-spacing: unset;
```
The `border-spacing` property may be specified as either one or two values.
- When **one** `<length>` value is specified, it defines both the horizontal and vertical spacings between cells.
- When **two** `<length>` values are specified, the first value defines the horizontal spacing between cells (i.e., the space between cells in adjacent _columns_), and the second value defines the vertical spacing between cells (i.e., the space between cells in adjacent _rows_).
### Values
- {{cssxref("<length>")}}
- : The size of the spacing as a fixed value.
## Formal definition
{{CSSInfo}}
## Formal syntax
{{csssyntax}}
## Examples
### Spacing and padding table cells
This example applies a spacing of `.5em` vertically and `1em` horizontally between a table's cells. Note how, along its outside edges, the table's `padding` values are added to its `border-spacing` values.
#### HTML
```html
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
```
#### CSS
```css
table {
border-spacing: 1em0.5em;
padding: 02em1em0;
border: 1pxsolidorange;
}
td {
width: 1.5em;
height: 1.5em;
background: #d2d2d2;
text-align: center;
vertical-align: middle;
}
```
#### Result
{{ EmbedLiveSample('Spacing_and_padding_table_cells', 400, 200) }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("border-collapse")}}, {{cssxref("border-style")}}
- The `border-spacing` property alters the appearance of the {{htmlelement("table")}} HTML element.
-[CSS table](/en-US/docs/Web/CSS/CSS_table) module