我正在尝试做一个固定的网格,无论在每个div
中添加什么内容,它都不会调整大小。我尝试过使用overflow:hidden
和minmax()
。
其思想是每个单独的框/部分将文本/图像放在每个框的中心。
body {
background-color: #15243a;
color: white;
font-family: "Whyte";
letter-spacing: 0.1em;
font-size: 14px;
margin: 0;
}
.grid {
position: absolute;
height: 100vh;
width: 100vw;
display: grid;
}
.grid-view div {
border: 1px solid white;
z-index: 99;
}
.top-nav {
grid-column: 1/12;
}
.top-left-1 {
grid-column: 1/4;
grid-row: 2/5;
}
.top-mid-left-1 {
grid-column: 1;
grid-row: 5;
}
.top-mid-left-2 {
grid-column: 2;
grid-row: 5;
}
.top-mid-left-3 {
grid-column: 3;
grid-row: 5;
}
.mid-left-span {
grid-column: 1/4;
grid-row: 6;
}
.bot-left-1 {
grid-column: 1;
grid-row: 7;
}
.bot-left-2 {
grid-column: 2;
grid-row: 7;
}
.bot-left-3 {
grid-column: 3;
grid-row: 7;
}
.mid-vertical-col {
grid-column: 4/6;
grid-row: 2/8;
}
.top-ill-con {
grid-column: 6/8;
grid-row: 2/4;
}
.mid-top-sq-1 {
grid-column: 6;
grid-row: 4;
}
.mid-top-sq-2 {
grid-column: 6;
grid-row: 5;
}
.mid-top-sq-3 {
grid-column: 6;
grid-row: 6;
}
.mid-top-sq-4 {
grid-column: 6;
grid-row: 7;
}
.top-right-box {
grid-column: 10 / 12;
grid-row: 2/6;
}
.mid-mid {
grid-column: 7/9;
grid-row: 4/6;
}
.bottom-span {
grid-column: 8/10;
grid-row: 7;
}
.bot-nav {
grid-column: 1/12;
}
<div class="grid grid-view">
<div class="top-nav"></div>
<div class="top-left-1"></div>
<div class="top-mid-left-1"></div>
<div class="top-mid-left-2"></div>
<div class="top-mid-left-3"></div>
<div class="mid-left-span"></div>
<div class="bot-left-1"></div>
<div class="bot-left-2"></div>
<div class="bot-left-3"></div>
<div class="mid-vertical-col"></div>
<div class="top-ill-con"></div>
<div class="mid-top-sq-1"></div>
<div class="mid-top-sq-2"></div>
<div class="mid-top-sq-3"></div>
<div class="mid-top-sq-4"></div>
<div class="mid-mid"></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div class="top-right-box"></div>
<div></div>
<div></div>
<div class="bottom-span"></div>
<div class="bot-nav"></div>
</div>
下面是一个Codepen:https://codepen.io/NiallColman49/pen/xxWwdZx .
1条答案
按热度按时间ufj5ltwl1#
在下面的代码中,无论网格中的内容是什么,每个网格项都将保持其宽度和高度。如果内容多于给定的空间,则会在其中滚动。我所做的不同之处在于,在
.grid
上设置了columns
和rows
的固定数量。然后,我在每个.grid-view div
上添加了overflow:auto
(CSS代码中有注解,我在那里添加了东西)。