gpt4 book ai didi

html - 在这种情况下如何解决网格布局问题?

转载 作者:太空宇宙 更新时间:2023-11-04 06:41:27 25 4
gpt4 key购买 nike

当我尝试使用网格布局制作我的部分时遇到了一些问题。我究竟在哪里犯错?有人可以解释一下吗?

HTML

<body>
<header>
<div class="grid-wrapper">
<div class="item1"><span>Item 1</span></div>
<div class="item2"><span>Item 2</span></div>
<div class="item3"><span>Item 3</span></div>
<div class="item4"><span>Item 4</span></div>
<div class="item5"><span>Item 5</span></div>
</div>
</header>
</body>

CSS

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
background-color: #969d9f;
}

header {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
background-color: #969d9f;
}

.grid-wrapper {
border: 1px solid red;
width: 1200px;
display: grid;
grid-gap: 20px;
grid-template-columns: repeat(2, 1fr);
}

.item1, .item2, .item3, .item4, .item5 {
border: 1px solid grey;
background-color: #636564;
height: 360px;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
font-size: 40px;
}

.item1 { width: 750px; }

.item2 { width: 360px; }

.item3 { width: 555px; }

.item4 { width: 555px; }

.item5 { width: 1200px; }

所以主要问题是如何正确显示我的 block 以及我犯的主要错误在哪里? 这是一些照片: This is how it looks right now And that's how I need to display them感谢您的关注!

最佳答案

这是我的意见

HTML

<body>
<header>
<div class="grid-wrapper">
<div class="item1"><span>Item 1</span></div>
<div class="item2"><span>Item 2</span></div>
<div class="item3"><span>Item 3</span></div>
<div class="item4"><span>Item 4</span></div>
<div class="item5"><span>Item 5</span></div>
</div>
</header>
</body>

CSS

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
background-color: #969d9f;
}

header {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
background-color: #969d9f;
}

.grid-wrapper {
border: 1px solid red;
width: 1200px;
display: grid;
grid-gap: 20px;
grid-template-areas: "item1 item1 item2" /* make grid area */
"item3 item4 item4"
"item5 item5 item5";

grid-template-columns:(1fr, 1fr, 1fr); /* set width of colums */
}



.item1, .item2, .item3, .item4, .item5 {
border: 1px solid grey;
background-color: #636564;
height: 360px;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
font-size: 40px;
}

.item1 {grid-area: item1} /* connect items with grid area */

.item2 {grid-area: item2}

.item3 {grid-area: item3}

.item4 {grid-area: item4}

.item5 {grid-area: item5}

关于html - 在这种情况下如何解决网格布局问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53725433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com