opacity应用代码实例

快乐打工仔 分类:实例代码

分享一段代码实例,它利用opacity实现了渐变的色块效果。

代码实例如下:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.pipipi.net/" />
<title>犀牛前端部落</title>
<style>
.row{overflow: hidden;}
.row div{
  width: 80px;
  height: 80px;
  line-height: 80px;
  text-align: center;
  float: left;
}
.row:nth-of-type(1) div{
  background-color: #000;
  color: #fff;
}
.row:nth-of-type(2) div{
  background-color: red;
}
.row:nth-of-type(3) div{
  background-color: green;
}
.row:nth-of-type(4) div{
  background-color: blue;
}
.row div:nth-child(1){
  background-color: #000;
  color: #fff;
}
.row div:nth-child(2){
  opacity: 1;
}
.row div:nth-child(3){
  opacity: 0.8;
}
.row div:nth-child(4){
  opacity: 0.6;
}
.row div:nth-child(5){
  opacity: 0.4;
}
.row div:nth-child(6){
  opacity: 0.2;
}
.row:nth-of-type(1) div{
  opacity: 1;
}
</style>
</head>
<body>
  <div class="demo">
    <div class="row">
      <div></div>
      <div>1</div>
      <div>0.8</div>
      <div>0.6</div>
      <div>0.4</div>
      <div>0.2</div>
    </div>
    <div class="row">
      <div>red</div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
    </div>
    <div class="row">
      <div>green</div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
    </div>		
    <div class="row">
      <div>blue</div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
      <div></div>
    </div>
  </div>
</body>
</html>

opacity应用代码实例,这样的场景在实际项目中还是用的比较多的,关于opacity应用代码实例就介绍到这了。

opacity应用代码实例属于前端实例代码,有关更多实例代码大家可以查看

回复

我来回复
  • 暂无回复内容