1 回答
TA贡献1796条经验 获得超4个赞
在 1220px 媒体查询中,添加一条规则以使第三个 div 居中。
@media (max-width: 1220px) {
.wrapper {
grid-template-columns: repeat(2, 400px);
}
/* NEW */
.box:last-child {
grid-column: 1 / 3;
justify-self: center;
width: 400px;
}
}
.wrapper {
display: grid;
grid-template-columns: 400px 400px 400px;
grid-auto-rows: 200px;
grid-gap: 10px;
grid-template-columns: repeat(3, 400px);
}
@media (max-width: 1220px) {
.wrapper {
grid-template-columns: repeat(2, 400px);
}
/* NEW */
.box:last-child {
grid-column: 1 / 3;
justify-self: center;
width: 400px;
}
}
@media (max-width: 810px) {
.wrapper {
grid-template-columns: repeat(1, 400px);
}
/* RESET */
.box:last-child {
grid-column: auto;
justify-self: stretch;
width: auto;
}
}
@media (max-width: 400px) {
.wrapper {
grid-template-columns: repeat(1, 300px);
}
}
.box {
background-color: red;
}
<div class="block bg-success">
<h1>Projects</h1>
<div class="wrapper">
<div class="box">A</div>
<div class="box">B</div>
<div class="box">C</div>
</div>
</div>
- 1 回答
- 0 关注
- 111 浏览
添加回答
举报