HTML Assignment Practice Table Practical
- Get link
- X
- Other Apps
1. Basic Table
<!DOCTYPE html>
<html>
<head>
<title>Basic Table</title>
</head>
<body>
<h1>Simple Table</h1>
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>Alice</td>
<td>25</td>
<td>New York</td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
<td>Los Angeles</td>
</tr>
</table>
</body>
</html>
2. Table with Row and Column Span
<!DOCTYPE html>
<html>
<head>
<title>Table with Span</title>
</head>
<body>
<h1>Table with Rowspan and Colspan</h1>
<table border="1">
<tr>
<th rowspan="2">Name</th>
<th colspan="2">Details</th>
</tr>
<tr>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>Alice</td>
<td>25</td>
<td>New York</td>
</tr>
</table>
</body>
</html>
3. Table with Inline CSS
<!DOCTYPE html>
<html>
<head>
<title>Table with Inline CSS</title>
</head>
<body>
<h1>Styled Table</h1>
<table style="border-collapse: collapse; width: 100%;">
<tr style="background-color: #f2f2f2;">
<th style="border: 1px solid #ddd; padding: 8px;">Name</th>
<th style="border: 1px solid #ddd; padding: 8px;">Age</th>
</tr>
<tr>
<td style="border: 1px solid #ddd; padding: 8px;">Alice</td>
<td style="border: 1px solid #ddd; padding: 8px;">25</td>
</tr>
</table>
</body>
</html>
4. Table with Internal CSS
<!DOCTYPE html>
<html>
<head>
<title>Table with Internal CSS</title>
<style>
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
}
th, td {
border: 1px solid black;
padding: 10px;
text-align: center;
}
th {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<h1>Styled Table with Internal CSS</h1>
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>Alice</td>
<td>25</td>
<td>New York</td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
<td>Los Angeles</td>
</tr>
</table>
</body>
</html>
5. Table with External CSS
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Table with External CSS</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Styled Table with External CSS</h1>
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Alice</td>
<td>25</td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
</tr>
</table>
</body>
</html>
CSS (styles.css
):
table {
width: 70%;
margin: 20px auto;
border-collapse: collapse;
border: 1px solid #ddd;
}
th, td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f4f4f4;
font-weight: bold;
}
6. Striped Table
<!DOCTYPE html>
<html>
<head>
<title>Striped Table</title>
<style>
table {
width: 80%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<h1>Striped Table</h1>
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Alice</td>
<td>25</td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
</tr>
</table>
</body>
</html>
7. Responsive Table
<!DOCTYPE html>
<html>
<head>
<title>Responsive Table</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
}
@media (max-width: 600px) {
table, th, td {
display: block;
width: 100%;
}
}
</style>
</head>
<body>
<h1>Responsive Table</h1>
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Alice</td>
<td>25</td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
</tr>
</table>
</body>
</html>
8. Table with Hover Effects
<!DOCTYPE html>
<html>
<head>
<title>Hover Effect Table</title>
<style>
table {
border-collapse: collapse;
width: 70%;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
}
tr:hover {
background-color: #f5f5f5;
}
</style>
</head>
<body>
<h1>Table with Hover Effects</h1>
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Alice</td>
<td>25</td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
</tr>
</table>
</body>
</html>
9. Table with Highlighted Header
<!DOCTYPE html>
<html>
<head>
<title>Table with Highlighted Header</title>
<style>
table {
width: 90%;
border-collapse: collapse;
}
th {
background-color: #4CAF50;
color: white;
padding: 10px;
}
td {
border: 1px solid #ddd;
padding: 8px;
}
</style>
</head>
<body>
<h1>Table with Highlighted Header</h1>
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Alice</td>
<td>25</td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
</tr>
</table>
</body>
</html>
10. Table with Images
<!DOCTYPE html>
<html>
<head>
<title>Table with Images</title>
<style>
table {
width: 70%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
}
img {
width: 50px;
height: 50px;
}
</style>
</head>
<body>
<h1>Table with Images</h1>
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>Profile</th>
</tr>
<tr>
<td>Alice</td>
<td>25</td>
<td><img src="alice.jpg" alt="Alice"></td>
</tr>
<tr>
<td>Bob</td>
<td>30</td>
<td><img src="bob.jpg" alt="Bob"></td>
</tr>
</table>
</body>
</html>
- Get link
- X
- Other Apps
Comments
Post a Comment