【发布时间】:2021-11-24 13:06:12
【问题描述】:
基本上,我使用 flexbox 和网格在 HTML/CSS 中构建网格以获得所需的布局。
我一直在 VSCode 中处理它,并设法让它看起来像我想要的那样(见下面的 img)。
当它在 WP 中呈现时,我的问题出现了,由于某种原因,框不会扩展以适应网格布局的大小,从而在内容中产生一些奇怪的间隙。 (见下文)
我使用了网格覆盖,我注意到网格的大小是正确的,只是盒子没有正确展开。
我不太确定问题出在哪里,我已经尝试调整布局、填充等。
HTML
main{
width: 100vw;
display: flex;
justify-content: space-around
}
.grid-section{
width: 100%;
max-width: 960px;
height: 100vh;
max-height: 250px;
background: #313131;
color: rgb(211, 168, 168);
font-size: 15px;
overflow:hidden;
border-radius: 10px;
display: flex;
justify-content: space-around
}
#grid{
display: grid;
grid-template-columns: repeat(32, 1fr);
grid-template-rows: 12% 44% 44% 0%
}
.box {
display: flex;
flex-basis: 100%;
}
/*top*/
.box:nth-child(1){
background: #9dcbe9;
grid-column: 1/33;
grid-row: 1/2;
padding: 5px;
}
/*left*/
.box:nth-child(2){
background: #eed875;
grid-column: 1/6;
grid-row: 2/4;
}
/*right*/
.box:nth-child(3){
background: #c97eec;
grid-column:28/33;
grid-row: 2/4;
}
/*middle long*/
.box:nth-child(4){
background: #9de99d;
grid-column: 6/28;
grid-row: 2/3;
}
/*mini boxes*/
.box:nth-child(5){
background: #ffa569;
grid-column: 6/9;
grid-row: 3/4;
}
.box:nth-child(6){
background: #584905;
grid-column: 9/14;
grid-row: 3/4;
}
.box:nth-child(7){
background: #560b79;
grid-column: 14/17;
grid-row: 3/4;
}
.box:nth-child(8){
background: #00ff00;
grid-column: 17/20;
grid-row: 3/4;
}
.box:nth-child(9){
background: #0a9ed8;
grid-column: 20/23;
grid-row: 3/4;
}
.box:nth-child(10){
background: #5802e2;
grid-column: 23/28;
grid-row: 3/4;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="stylesheet.css">
</head>
<title> flexBox testing</title>
<body>
<main>
<div id="grid" class="grid-section">
<div class="box">
<div class="box-content">n1</div>
</div>
<div class="box">
<div class="box-content">n2</div>
</div>
<div class="box">
<div class="box-content">n3</div>
</div>
<div class="box">
<div class="box-content">n4</div>
</div>
<div class="box">
<div class="box-content">n5</div>
</div>
<div class="box">
<div class="box-content">n6</div>
</div>
<div class="box">
<div class="box-content">n7</div>
</div>
<div class="box">
<div class="box-content">n8</div>
</div>
<div class="box">
<div class="box-content">n9</div>
</div>
<div class="box">
<div class="box-content">n10</div>
</div>
</div>
</main>
</body>
提前致谢
【问题讨论】:
-
您问题中的代码有效。在 WP 中运行代码时会发生一些变化。也许一些 WP 代码会覆盖你所拥有的。没有看到 WP 代码真的帮不了你。