CSS (Cascading Style Sheets) is a style sheet language used for describing the presentation of a document written in HTML (Hypertext Markup Language). CSS provides a wide range of properties to style the elements of a web page. One such property is border-spacing.
Border-spacing is a CSS property used to set the distance between the borders of adjacent table cells. It is used to create space between the cells and make the table look more visually appealing. The property is applied to the <table>
element and not to the individual cells.
The border-spacing property takes two values, the horizontal spacing and the vertical spacing. The values can be specified in pixels, ems, rems, or percentages. If only one value is specified, it is applied to both the horizontal and vertical spacing. If two values are specified, the first value is applied to the horizontal spacing and the second value is applied to the vertical spacing.
Border-spacing is used to create space between the borders of adjacent table cells. It is a useful property when you want to create a visually appealing table with some space between the cells. The property is applied to the <table>
element and not to the individual cells.
Let's take a look at an example to understand how border-spacing works:
<table style="border-spacing: 10px;">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</table>
In the above example, we have set the border-spacing property to 10 pixels. This will create a space of 10 pixels between the borders of adjacent cells. The result will look something like this:
Cell 1 | Cell 2 |
Cell 3 | Cell 4 |
You can also specify different values for the horizontal and vertical spacing. For example:
<table style="border-spacing: 10px 5px;">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</table>
In the above example, we have set the horizontal spacing to 10 pixels and the vertical spacing to 5 pixels. The result will look something like this:
Cell 1 | Cell 2 |
Cell 3 | Cell 4 |
You can also set the border-spacing property using CSS classes or IDs. For example:
.my-table {
border-spacing: 10px;
}
Or:
#my-table {
border-spacing: 10px;
}
Here are some code examples to help you understand how to use the border-spacing property:
<table style="border-spacing: 10px;">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</table>
<table style="border-spacing: 10px 5px;">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</table>
Border-spacing is a useful CSS property that allows you to create space between the borders of adjacent table cells. It is applied to the <table>
element and not to the individual cells. The property takes two values, the horizontal spacing and the vertical spacing, and can be specified in pixels, ems, rems, or percentages. By using border-spacing, you can create visually appealing tables with some space between the cells.