box-shadow調節背景色

box-shadow瀏覽器支持狀況:html

 

經過box-shadow調節背景色。下面的例子實現box:hover變暗20%。通常來說hover背景色變暗都是給一個色值就行了。可是若是背景色是動態的,好比後端返回的。這個時候用shadow比較合適。後端

 

演示在這裏:https://jsfiddle.net/nyp69r2L/瀏覽器

 

box-shadow:inset 0 0 0 99999px rgba(0,0,0,0.2);ide

inset:將外部陰影 (outset) 改成內部陰影。ui

0 0 0 99999px:shadow大小。spa

rgba(0,0,0,0.2):shadow顏色。black的0.2透明度。.net

 

body{
  margin:50px;
  background-color:#2C3437;
}
.content{
  width:360px;
  height:250px;
  margin-left:auto;
  margin-right:auto;
  background-color:lightgray;
}
.inside{
  float:left;
  width:100px;
  height:100px;
  margin:15px 10px 0 10px;
}
.inside:hover{
  box-shadow:inset 0 0 0 99999px rgba(0,0,0,0.2);
}

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
<body>
    <div class="content">
        <div class="inside" style="background-color:gray;"></div>
        <div class="inside" style="background-color:green;"></div>
        <div class="inside" style="background-color:yellow;"></div>
        <div class="inside" style="background-color:orange;"></div>
        <div class="inside" style="background-color:pink;"></div>
        <div class="inside" style="background-color:lightblue;"></div>
    </div>
  </body>
</html>
相關文章
相關標籤/搜索