All:
I am pretty new to CSS. One Data visualization user case I try to implement(I use D3.js) is :
Say there are several DIVs overlap each other, the one clicked will show on the top layer,I wonder how can I set its z-index when all DIVs z-index are "auto"?(for certain reason like data binding, I can not adjust its location in the DOM tree)?
The main difficulties that I have is: How to determine the starting minimum z-index for those DIVs( because there are some other elements, even I can give a higher z-index to the one clicked and lower for all other DIVs, but the number still can possibly be smaller than other elements) So, if I can get that z-index, I do not need to know what it is, but as long as I can increase it to make sure the clicked one has higher number than that, then it is done.
Or is there other ways to do this?
var container = d3.select("body")
.append("div")
.classed("random", true)
.style("position", "fixed")
.style({
"top":"50px",
"width":"200px",
"height":"200px",
"background-color":"rgba(100,100,100, 0.5)"
})
var color = d3.scale.category20();
container.selectAll("span")
.data([1,2,3,4])
.enter()
.append("span")
.style({
"position":"absolute",
"width":"50px",
"height":"50px"
})
.style("margin", function(d,i){
return i*10+10+"px";
})
.style("background-color", function(d, i){
return color(i);
})
.text(function(d, i){
return d;
})
container.selectAll("span")
.on("click", function(d, i){
var block = d3.select(this);
// this is the part I can not figure out ================
block.moveToFront();
});