gpt4 book ai didi

css-grid 媒体查询没有响应

转载 作者:行者123 更新时间:2023-12-05 02:13:49 25 4
gpt4 key购买 nike

我正在使用网格,出于某种原因,在媒体查询中使用 max-width 似乎没有任何作用。代码如下:

代码:

body {
color: #fff;
text-align: center;
}

#content {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-auto-rows: minmax(100px, auto);
grid-gap: 1rem;
grid-template-areas: 'header header header header' 'block_1 block_1 block_2 block_2'
}

@media only screen and (max-width:700px) {
#content {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-auto-rows: minmax(100px, auto);
grid-gap: 1rem;
grid-template-areas: 'header' 'block_1' 'block_2'
}
}

#content>* {
background-color: #fff;
border: 1px solid black;
}

.header {
grid-area: header;
height: 150px;
}

.block_1 {
grid-area: block_1;
height: 150px;
}

.block_2 {
grid-area: block_2;
height: 150px;
}
<!doctype html>

<html>

<head>
<link rel="stylesheet" type="text/css" href="master.css">
</head>

<body>
<div id='content'>
<div class='header'>Header</div>
<div class='block_1'>Header</div>
<div class='block_2'>Header</div>
</div>
</body>

</html>

我希望这 2 个 block 类在 699 像素及以下的位置相互堆叠。然而,他们似乎并不想这样做。

最佳答案

您还需要更改 grid-template-columns: repeat(1, 1fr); 以使该网格占据全宽。

body {
color: #fff;
text-align: center;
}

#content {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-auto-rows: minmax(100px, auto);
grid-gap: 1rem;
grid-template-areas: 'header header header header' 'block_1 block_1 block_2 block_2'
}

@media only screen and (max-width:700px) {
#content {
display: grid;
grid-template-columns: repeat(1, 1fr);
grid-auto-rows: minmax(100px, auto);
grid-gap: 1rem;
grid-template-areas: 'header' 'block_1' 'block_2'
}
}

#content>* {
background-color: #fff;
border: 1px solid black;
}

.header {
grid-area: header;
height: 150px;
}

.block_1 {
grid-area: block_1;
height: 150px;
}

.block_2 {
grid-area: block_2;
height: 150px;
}
<!doctype html>

<html>

<head>
<link rel="stylesheet" type="text/css" href="master.css">
</head>

<body>
<div id='content'>
<div class='header'>Header</div>
<div class='block_1'>Header</div>
<div class='block_2'>Header</div>
</div>
</body>

</html>

关于css-grid 媒体查询没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54535850/

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