z-index attribute Introduction
- Only we will set positioning to use the
z-index
property, such as:固定定位
,相对定位
,绝对定位
. - The positioning element default
z-index
attribute value is0
. - If the
2
elements are not provided positioningz-index
properties, which will cover the former. - If the
2
positioning elements are provided withz-index
attributes, and the values will be as large as to cover the former or the latter. z-index
Properties of large value will cover small, it is to set the level of the element.
z-index attribute Practice
Practice has proved that with these words, if
2
the elements are not set positioningz-index
properties, which will cover the former.-
Block
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>z-index属性</title>
<style>
div{
width: 200px;
height: 200px;
}
.div1{
background-color: red;
position: relative;
top: 50px;
left: 50px;
}
.div2{
background-color: slateblue;
position: relative;
left: 100px;
}
</style>
</head>
<body>
<div class="div1"></div>
<div class="div2"></div>
</body>
</html>
-
Results Figure
- With practice to prove this statement, if
2
the element positioning are set upz-index
property, and the value is as large as the latter will cover the former. -
Block
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>z-index属性</title>
<style>
div{
width: 200px;
height: 200px;
}
.div1{
background-color: red;
position: relative;
top: 50px;
left: 50px;
z-index: 2;
}
.div2{
background-color: slateblue;
position: relative;
left: 100px;
z-index: 2;
}
</style>
</head>
<body>
<div class="div1"></div>
<div class="div2"></div>
</body>
</html>
-
Results Figure
Use practices to prove it,
z-index
a large property value of the property will cover small, it is to set the level of the element.-
Block
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>z-index属性</title>
<style>
div{
width: 200px;
height: 200px;
}
.div1{
background-color: red;
position: relative;
top: 50px;
left: 50px;
z-index: 3;
}
.div2{
background-color: slateblue;
position: relative;
left: 100px;
z-index: 2;
}
</style>
</head>
<body>
<div class="div1"></div>
<div class="div2"></div>
</body>
</html>
-
Results Figure