A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/html-css-exercise/css-properties/border-spacing-answer.php below:

Website Navigation


CSS Properties: How to set the border-spacing for a table?

CSS Properties: How to set the border-spacing for a table?Last update on February 19 2024 13:01:58 (UTC/GMT +8 hours)

Go to Exercise page

Solution:

HTML Code:

<!DOCTYPE html><!-- Declares the document type as HTML -->
<html><!-- Root element of the HTML document -->
<head><!-- Contains metadata about the HTML document -->
<title>How to set the border-spacing for a table</title><!-- Sets the title of the HTML document -->
<style type="text/css"> /* Begins a CSS style block */
table.xyz1 { /* Defines a CSS rule for tables with the class 'xyz1' */
border-collapse: separate; /* Sets the border collapse behavior to separate, ensuring spacing between table cells */
border-spacing: 5px; /* Sets the spacing between table cells to 5 pixels */
border-color: #22CF64; /* Sets the color of the table border to #22CF64 */
}
table.xyz2 { /* Defines a CSS rule for tables with the class 'xyz2' */
border-collapse: separate; /* Sets the border collapse behavior to separate, ensuring spacing between table cells */
border-spacing: 5px 20px; /* Sets the horizontal and vertical spacing between table cells to 5 pixels and 20 pixels respectively */
border-color: #22CF64; /* Sets the color of the table border to #22CF64 */
}
</style><!-- Ends the CSS style block -->
</head><!-- Ends the head section of the HTML document -->
<body><!-- Contains the content of the HTML document -->
<p>w3resource Tutorial</p><!-- Displays the text 'w3resource Tutorial' within a paragraph element -->
<table class="xyz1" border="2"><!-- Creates a table with class 'xyz1' and a border of 2 pixels -->
<tr><!-- Begins a table row -->
<td>HTML5</td><!-- Defines a table data cell with the text 'HTML5' -->
<td>JavaScript</td><!-- Defines a table data cell with the text 'JavaScript' -->
</tr><!-- Ends the table row -->
<tr><!-- Begins another table row -->
<td>PHP</td><!-- Defines a table data cell with the text 'PHP' -->
<td>CSS3</td><!-- Defines a table data cell with the text 'CSS3' -->
</tr><!-- Ends the table row -->
</table><!-- Ends the table -->
<br><!-- Inserts a line break -->
<table class="xyz2" border="2"><!-- Creates another table with class 'xyz2' and a border of 2 pixels -->
<tr><!-- Begins a table row -->
<td>HTML5</td><!-- Defines a table data cell with the text 'HTML5' -->
<td>JavaScript</td><!-- Defines a table data cell with the text 'JavaScript' -->
</tr><!-- Ends the table row -->
<tr><!-- Begins another table row -->
<td>PHP</td><!-- Defines a table data cell with the text 'PHP' -->
<td>CSS3</td><!-- Defines a table data cell with the text 'CSS3' -->
</tr><!-- Ends the table row -->
</table><!-- Ends the table -->
</body><!-- Ends the body section of the HTML document -->
</html><!-- Ends the HTML document -->

Explanation:

Live Demo:

See the Pen border-spacing-answer by w3resource (@w3resource) on CodePen.

See the solution in the browser

Supported browser

Go to Exercise page

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4