CSS网格被覆盖,我不知道为什么
我正在尝试创建一个4 x 4个正方形(Divs)的4 x 4网格。我已经制作了带有网格显示的容器div。 16个正方形是行的,但是当我尝试制作4列时,它在开发工具的“样式”选项卡中具有罢工。
这是我在CSS中拥有的:
html,body{
height: 100%;
margin: none;
}
#heading{
height: 250px;
}
#wrapper{
width: 600px;
height: 600px;
margin-left: auto;
margin-right: auto;
}
#container{
border: solid 1px;
display: grid;
grid-template-columns: 25%, 25%, 25%, 25%;
height: 600px;
width: auto;
}
.squares{
border: solid 1px rgba(0, 0, 0, 0.3);
}
他们由JS创建了16个孩子。这会影响为什么网格无法正常工作吗?
let x = 0;
do{
const square = document.createElement("div");
square.className = "squares";
square.setAttribute("id","block");
document.getElementById("container").appendChild(square);
x++;
}
while(x < 16);
I am trying to create a 4 x 4 grid of 16 squares(divs). I have made the container div with a grid display. The 16 squares are in rows but when I try to make 4 columns it has a strikethrough in the styles tab of the dev tools.
Here is what I have in my CSS:
html,body{
height: 100%;
margin: none;
}
#heading{
height: 250px;
}
#wrapper{
width: 600px;
height: 600px;
margin-left: auto;
margin-right: auto;
}
#container{
border: solid 1px;
display: grid;
grid-template-columns: 25%, 25%, 25%, 25%;
height: 600px;
width: auto;
}
.squares{
border: solid 1px rgba(0, 0, 0, 0.3);
}
They 16 child divs are created with JS. Would that have an impact on why grid is not working as expected?
let x = 0;
do{
const square = document.createElement("div");
square.className = "squares";
square.setAttribute("id","block");
document.getElementById("container").appendChild(square);
x++;
}
while(x < 16);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需在
,
之间,网格 - 板块列
值。您也可以将其更改为
自动
,而不是自己进行计算,如果它们都相同并指定25%
。现在看看
No need for the
,
between thegrid-template-columns
values.You can also change it to
auto
instead of doing the calculation yourself if they are all the same and specify25%
.take a look now
逗号正在干扰
网格 - 板块柱
,如果您这样做:应该解决上述问题
The commas are interfering with the
grid-template-columns
, if you do:should fix the mentioned issue