我试图在更大的网格内绘制一个小网格。使用 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;
}
现在,主网格要么是隐藏的,要么没有加载分配给它的css,你可以通过它取代单元格的事实来判断它存在的唯一方法。
理想情况下,单元格将位于标准网格和素格栅格的顶部,并且素格网格将正确使用定义的样式。
js小提琴
你需要一个
prime.style.position = 'absolute'
和
cell.style.positon = 'relative'
添加到 z 索引中。
在这里查看 http://jsfiddle.net/7MJpf/5/