How z-index properties used in CSS

z-index attribute Introduction

  • Only we will set positioning to use the z-indexproperty, such as: 固定定位, 相对定位, 绝对定位.
  • The positioning element default z-indexattribute value is 0.
  • If the 2elements are not provided positioning z-indexproperties, which will cover the former.
  • If the 2positioning elements are provided with z-indexattributes, and the values will be as large as to cover the former or the latter.
  • z-indexProperties 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 2the elements are not set positioning z-indexproperties, 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 2the element positioning are set up z-indexproperty, 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-indexa 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

Guess you like

Origin www.cnblogs.com/lq0001/p/12116422.html