CSS z-index
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: attribute value;
There are three options for CSS z-index attribute values, namely auto, number and inherit. The effect of the attributes is as follows- 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
<style type="text/css">
img{
position:absolute;
left:0px;
top:0px;
z-index:-1;
}
</style>
Here is the text introduction<img src="example picture">
Rendering effectimg{
position:absolute;
left:0px;
top:0px;
z-index:-1;
}
</style>
Here is the text introduction<img src="example picture">
Here is the text introduction
CSS z-index example two, multiple blocks overlap effect
<style type="text/css">
#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>
Present results#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>
Pay attention to the effect of stacking the three colored square blocks. The upper and left positions of each square block are different, but they are all set to absolute positions, with different values of z-index ( The effects are 1, 2, and 3).
Post a Comment
0 Comments