在第三个元素之后添加一个元素时,元素应该出现在侧面而不是下面,正如它所写的那样,grid-template-rows: 1fr 1fr 1fr;
但这不会发生,为什么?
document.querySelector(".btn").onclick = ()=>{
let x = document.createElement("div")
x.classList.add("item")
document.querySelector(".content").appendChild(x)
let y = document.querySelectorAll(".item")
}
*{
margin:0;
padding:0;
box-sizing:border-box;
}
.container{
width: 600px;
height: 400px;
background-color: blanchedalmond;
}
.content{
border:1px solid black;
display: grid;
grid-template-rows: 1fr 1fr 1fr;
}
.item{
width:300px;
height:50px;
background-color: cornflowerblue;
border:1px solid black;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel = "stylesheet" href = "style.css">
</head>
<body>
<div class="container">
<div class="content">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<button class = "btn">+</button>
</div>
<script src="script.js"></script>
</body>
</html>
1 个回答