box-shadow调节背景色

box-shadow浏览器支持情况:

通过box-shadow调节背景色。下面的例子实现box:hover变暗20%。一般来讲hover背景色变暗都是给一个色值就好了。但是如果背景色是动态的,比如后端返回的。这个时候用shadow比较合适。

演示在这里:https://jsfiddle.net/nyp69r2L/

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

inset:将外部阴影 (outset) 改为内部阴影。

0 0 0 99999px:shadow大小。

rgba(0,0,0,0.2):shadow颜色。black的0.2透明度。

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>
原文地址:https://www.cnblogs.com/wuyahuang/p/4504330.html