代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>grid</title>
<style>
html,body{
margin: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.list{
position: relative;
display: grid;
width: 300px;
grid-template-columns: repeat(3,1fr);
list-style: none;
padding: 0;
counter-reset: count;
gap: 2px;
}
.item{
aspect-ratio: 1; /*宽高比1:1*/
background-color: #eee;
}
.item:nth-child(9)~.item{ /*选择第9个以后的元素*/
position: absolute;
width: calc(100% / 3 - 1px);
counter-increment: count; /* 从第10个开始计数 */
visibility: hidden;
right: 0;
bottom: 0;
}
.item:nth-child(9)~.item:last-child::before{
visibility: visible;
background-color: rgba(0,0,0,.2);
}
.item:nth-child(9)~.item::before{
content: '+' counter(count);
display: grid;
height: 100%;
place-content: center;
font-size: 30px;
color: #fff;
}
</style>
</head>
<body>
<ul class="list" id="list">
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
</ul>
<div>
<button onclick="add()">add</button>
<button onclick="remove()">remove</button>
</div>
<script>
function add() {
const item = document.createElement('li');
item.className = "item";
list.append(item)
}
function remove() {
list.removeChild(list.lastElementChild)
}
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。