我想要在更大的网格内绘制一个小网格。使用zIndex似乎根本不起作用,我不知道该如何做。网格里面的网格Javascript和jQuery:
代码绘制网格
的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;
}
眼下的首要网格隐藏或不加载分配给它的CSS,你可以告诉它的存在是由它取代的细胞这一事实的唯一途径。
理想情况下,单元格将位于标准网格和主要网格的顶部,并且主要网格将正确使用定义的样式。
首先,你的首要电网拼错'className'。 – voithos
这是对未加载的CSS进行排序。谢谢:) –