我正在创建一个带有包含表格的弹出框的网站。经过数小时的尝试,尝试使用具有 table-layout 属性的其他组合,表格仍无法统一呈现。 CSS如下所示。
#popup {
position: absolute;
height: 50%;
width: 50%;
left: 25%;
top: 25%;
background: white;
border: solid black 1px;
text-align: center;
}
table{
table-layout: fixed; /* Cells are uniformly sized */;
width: 100%;
height: 100%;
}
呈现了下表。
如何确保所有单元格大小一致?
答案 0 :(得分:-1)
我相信您最好使用CSS Grid进行这种布局。
要学习CSS网格,我建议您使用Grid Garden和Grid Critters游戏化教程(后者确实收费)。两家公司也都有flexbox教程(Flexbox Froggy和Flexbox Zombies都是免费的)
无论如何,这是使用Grid进行的布局的可执行复制:
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
display: flex;
justify-content: center;
background-image: url("https://cdn.pixabay.com/photo/2017/09/14/22/42/milky-way-2750627_960_720.jpg") ;
}
.wrap {
display: flex;
flex-direction: column;
align-items: center;
background-color: white;
border: 1px solid black;
border-radius: 5px;
width: 90%;
padding: 0 10px;
}
.grid {
align-self: stretch;
padding-bottom: 15px;
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 5px;
justify-content: center;
align-items: center;
}
.heading, .col-1 {
display: flex;
align-items: center;
justify-content: center;
}
.heading {
font-size: 1.5em;
font-weight: bold;
padding-top: 10px;
}
.col-1 {
background-color: #D3D3D3;
height: 100px;
border: 1px solid black;
}
.blank {
grid-column: 2 / span 3;
}
<div class="wrap">
<h2>Date</h2>
<div class="grid">
<div class="heading">
H103
</div>
<div class="blank"></div>
<div class="col-1">Period 1</div>
<div class="col-1">Period 2</div>
<div class="col-1">Period 3</div>
<div class="col-1">Period 4</div>
<div class="heading">
H104
</div>
<div class="blank"></div>
<div class="col-1">Period 1</div>
<div class="col-1">Period 2</div>
<div class="col-1">Period 3</div>
<div class="col-1">Period 4</div>
<div class="heading">
H105
</div>
<div class="blank"></div>
<div class="col-1">Period 1</div>
<div class="col-1">Period 2</div>
<div class="col-1">Period 3</div>
<div class="col-1">Period 4</div>
<div class="heading">
H107
</div>
<div class="blank"></div>
<div class="col-1">Period 1</div>
<div class="col-1">Period 2</div>
<div class="col-1">Period 3</div>
<div class="col-1">Period 4</div>
</div>
</div>