I want to be able to have each cell in the header row (at the top) keep the same width (in pixels) regardless of what the bottom table is. The image shows an example with 12 columns in the bottom table.
I am using python to generate the HTML, and so I can get the number of columns and then do colspan depending on the number to get the top row to be close enough. I'm wondering if there is a better way? I considered making the bottom table inside one cell, but I want it to look seamless and I'm not sure how to do that either
I want to be able to have each cell in the header row (at the top) keep the same width (in pixels) regardless of what the bottom table is. The image shows an example with 12 columns in the bottom table.
I am using python to generate the HTML, and so I can get the number of columns and then do colspan depending on the number to get the top row to be close enough. I'm wondering if there is a better way? I considered making the bottom table inside one cell, but I want it to look seamless and I'm not sure how to do that either
Share Improve this question edited Nov 21, 2024 at 0:27 Barmar 783k56 gold badges547 silver badges660 bronze badges asked Nov 21, 2024 at 0:25 AeneasAeneas 11 bronze badge 2 |1 Answer
Reset to default 0To have all rows in a table maintain columns of equal width, irrespective of the number of columns in other rows, we cab use flexbox layout.
.table {
display: flex;
flex-direction: column;
border: 1px solid #ddd;
width: 100%;
}
.row {
display: flex;
width: 100%;
}
.row .cell {
flex: 1;
border: 1px solid #ddd;
padding: 10px;
text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="table">
<div class="row">
<div class="cell">Row 1 - Col 1</div>
<div class="cell">Row 1 - Col 2</div>
<div class="cell">Row 1 - Col 3</div>
</div>
<div class="row">
<div class="cell">Row 2 - Col 1</div>
<div class="cell">Row 2 - Col 2</div>
</div>
<div class="row">
<div class="cell">Row 3 - Col 1</div>
<div class="cell">Row 3 - Col 2</div>
<div class="cell">Row 3 - Col 3</div>
<div class="cell">Row 3 - Col 4</div>
</div>
</div>
</body>
</html>
There are some advantages to of this as well, like, no need to give specific width to the columns, and also, the table will adjust according to the screen width.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742321030a4421810.html
style="width: XXX"
to specify the width of eachth
. – Barmar Commented Nov 21, 2024 at 0:28