HTML Code :
<!DOCTYPE html><!-- Declares the document type and version of HTML -->
<html><!-- Begins the HTML document -->
<head><!-- Contains metadata and links to external resources -->
<title>How to set the table layout algorithm</title><!-- Sets the title of the document -->
<style type="text/css"> /* Starts CSS styling */
table { /* Styles all table elements */
border-collapse: separate; /* Specifies the border-collapse property to separate */
width: 100%; /* Sets the width of the table to 100% */
border: 2px solid #CC63FF; /* Sets the border of the table */
}
td { /* Styles all table cell elements */
border: 2px solid #FF36CC; /* Sets the border of the table cells */
}
table.w3r1 { /* Styles tables with the class "w3r1" */
table-layout: auto; /* Sets the table layout algorithm to auto */
}
table.w3r2 { /* Styles tables with the class "w3r2" */
table-layout: fixed; /* Sets the table layout algorithm to fixed */
}
</style><!-- Ends CSS styling -->
</head><!-- Ends the head section -->
<body><!-- Begins the body of the document -->
<p><strong>w3resource Tutorial</strong></p><!-- Displays a paragraph with bold text "w3resource Tutorial" -->
<p>table-layout: auto</p><!-- Displays a paragraph with the text "table-layout: auto" -->
<table class="w3r1"><!-- Begins a table with the class "w3r1" -->
<tr><!-- Begins a table row -->
<td width="5%">w3resource web development tutorial</td><!-- Defines a table cell with 5% width and text content -->
<td width="95%">JavaScript Tutorial</td><!-- Defines a table cell with 95% width and text content -->
</tr><!-- Ends the table row -->
</table><!-- Ends the table -->
<p>table-layout: fixed</p><!-- Displays a paragraph with the text "table-layout: fixed" -->
<table class="w3r2"><!-- Begins a table with the class "w3r2" -->
<tr><!-- Begins a table row -->
<td width="5%">w3resource web development tutorial</td><!-- Defines a table cell with 5% width and text content -->
<td width="95%">JavaScript Tutorial</td><!-- Defines a table cell with 95% width and text content -->
</tr><!-- Ends the table row -->
</table><!-- Ends the table -->
</body><!-- Ends the body section -->
</html><!-- Ends the HTML document -->
Explanation:
Live Demo :
See the Pen table-layout-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
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