CSS z-index syntax example
The purpose of CSS z-index grammar is to control the position of the z-axis. This requires a little space to explain. Assuming that facing a computer screen, the left and right directions are the x-axis, and the up and down are the y-axis, so the direction facing you is z Shaft! The larger the value of z-index, the closer you are to yourself. On the contrary, if the value of z-index is smaller, it means that you are farther away from yourself!
The use of z-index grammar alone is actually not enough to create a stacking effect of blocks or pictures, because z-index can only set the z-axis position of the block, and it must be combined with the position grammar to set the position of the block. To make a stacking effect, the following example is a simple special effect of z-index and position .
CSS z-index basic syntax
- z-index:auto; // Default value, the order of stacking is the same as the parent layer.
- z-index:number; // Decide the stacking order according to number, the larger the number, the higher the layer.
- z-index:inherit; // inherited from the stacking order of the parent layer
CSS z-index example one, with position example
img{
position:absolute;
left:0px;
top:0px;
z-index:-1;
}
</style>
Here is the text introduction<img src="example picture">
CSS z-index example two, multiple blocks overlap effect
#p1{
position:absolute;
top:10px;
left:10px;
width:150px;
height:150px;
background-color:#00dc03;
z-index:1;
}
#p2{
position:absolute;
top:20px;
left:20px;
width:150px;
height:150px;
background-color:#fdff55;
z-index:2;
}
#p3{
position:absolute;
top:30px;
left:30px;
width :150px;
height:150px;
background-color:#ff1c19;
z-index:3;
}
</style>
<div id="p1"></div>
<div id="p2"></div>
<div id="p3"></div>
Post a Comment
0 Comments