gpt4 book ai didi

javascript - 网格内的网格 Javascript 和 JQuery :

转载 作者:行者123 更新时间:2023-11-29 14:58:10 25 4
gpt4 key购买 nike

我正在尝试在较大的网格内绘制一个小网格。使用 zIndex 似乎根本不起作用,我没有主意。

绘制网格的代码

Javascript/JQuery:

function creategrid(size){

var primeW = Math.floor((400) / size),
primeH = Math.floor((250) / size),
standardW = Math.floor((500) / size),
standardH = Math.floor((500) / size);

var standard = document.createElement('div');
standard.className = 'grid';
standard.style.width = (standardW * size) + 'px';
standard.style.height = (standardH * size) + 'px';

var prime = document.createElement('div');
prime.clasName = 'gridprime';
prime.style.width = (primeW * size) + 'px';
prime.style.height = (primeH * size)+ 'px';
prime.style.zIndex= '-1';
standard.appendChild(prime);

for (var i = 0; i < standardH; i++) {
for (var p = 0; p < standardW; p++) {
var cell = document.createElement('div');
cell.style.height = (size - 1) + 'px';
cell.style.width = (size - 1) + 'px';
cell.style.zIndex= '10';
standard.appendChild(cell);
}
}

document.body.appendChild(standard);
}

creategrid(10);

用于区分网格的 CSS。

CSS:

  .grid {
margin: 0px auto auto;
border: 1px solid #ccc;
border-width: 0 1px 1px 0;
background-color: #28ACF9;
}

.grid div {
border: 1px solid #ccc;
border-width: 1px 0 0 1px;
float: left;
}

.gridprime {
margin-top: 50px ;
margin-left: 50px;
border: 1px solid #000;
color: #FFFF33;
float: left;
}

现在 prime grid 要么被隐藏,要么没有加载分配给它的 css,你可以告诉它存在的唯一方法是它取代了单元格。

理想情况下,单元格将位于标准网格和主要网格之上,并且主要网格将正确使用定义的样式。

jsFiddle

最佳答案

你需要一个

prime.style.position = 'absolute'

cell.style.positon = 'relative'

已添加到您的 z-indexes。

在这里查看 http://jsfiddle.net/7MJpf/5/

关于javascript - 网格内的网格 Javascript 和 JQuery :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14464913/

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