-
Hajipur, Bihar, 844101
HTML tables are used to display tabular data. CSS allows you to style tables for better presentation, readability, spacing, and responsiveness.
<table>
– Defines the table
<tr>
– Table row
<td>
– Table cell
<th>
– Table header
<thead>
, <tbody>
, <tfoot>
– Table sections
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
}
border-collapse
collapse
: Merges adjacent borders
separate
: Keeps borders separate (default)
table {
border-collapse: collapse;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
}
th {
background-color: #04AA6D;
color: white;
text-align: left;
}
table {
width: 80%;
margin: auto;
text-align: center;
}
.table-container {
overflow-x: auto;
}
table {
width: 100%;
min-width: 600px;
}
Wrap table in:
<div class="table-container">
<table>...</table>
</div>
Q1. Add 1px solid border to table cells.
Q2. Collapse borders in a table.
Q3. Add 10px padding to table cells.
Q4. Change table header background to dark blue and text to white.
Q5. Alternate table row background colors.
Q6. Center-align text inside all cells.
Q7. Add hover effect to table rows.
Q8. Set table width to 80% and center it.
Q9. Make table horizontally scrollable on smaller screens.
Q10. Apply bold font to the first column in each row.
Q1: Which property merges table cell borders?
Q2: Which tag represents a row in an HTML table?
Q3: How do you add padding to table cells?
Q4: What does tr:hover do?
Q5: Which tag is used for a table header cell?
Q6: What is the default value of border-collapse?
Q7: Which pseudo-class is used to style even rows?
Q8: How to center-align all text in table?
Q9: How to make a table responsive horizontally?
Q10: Which section tags can a table contain?