加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
grid.html 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
王建立 提交于 2021-07-12 22:49 . 添加css demo
<!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>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化