CSS阴影效果

时间:2016-07-26 23:02:16

标签: css css3

有谁知道如何使用CSS实现以下效果? (我指的是每个圆圈之间的阴影)

enter image description here

到目前为止,我的HTML看起来像这样:

<div>
    <div class="psa-circle-container"><span class="psa-circle">12</span><br>CIUDADES</div>

    <div class="psa-circle-container"><span class="psa-circle">3</span><br>
    EQUIPOS POR CIUDAD</div>

    <div class="psa-circle-container"><span class="psa-circle">18</span><br>
    JUGADORES POR EQUIPO</div>

</div>

这是我的css:

.psa-circle {
    font-size: 35px;
    line-height: 70px;
    display: inline-block;
    width: 70px;
    height: 70px;
    background: white;
    border-radius: 50%;
    margin: 30px;
    box-shadow: inset 0 0 5px #000000;
    color: black;
}
.psa-circle-container {
    display: inline-block;
    text-align: center;
    color: white;
    padding: 20px;
    width: 180px;
    vertical-align: top;
    font-size: 18px;
    font-weight: bold;
    margin: 0 20px 20px;
    padding-top: 0;
}

完成此任务:

enter image description here

我曾尝试使用&#34; psa-circle-container&#34;插入阴影但没有成功。我尝试使用谷歌搜索阴影效果,但我还没有找到类似的东西。

2 个答案:

答案 0 :(得分:5)

您可以使用伪元素,例如::before

&#13;
&#13;
.psa-circle {
  font-size: 35px;
  line-height: 70px;
  display: inline-block;
  width: 70px;
  height: 70px;
  background: white;
  border-radius: 50%;
  margin: 30px;
  box-shadow: 0 0 5px #000000;
  color: black;
}
.psa-circle-container {
  float: left;
  text-align: center;
  color: white;
  padding: 20px;
  width: 120px;
  vertical-align: top;
  font-size: 18px;
  font-weight: bold;
  background: steelblue;
  height: 170px;
  position: relative;
  overflow: hidden;
}
.psa-circle-container ~ .psa-circle-container::before {
  content: '';
  position: absolute;
  top: 10px;
  bottom: 10px;
  width: 40px;
  left: -45px;
  background: transparent;
  border-radius: 50%;
  box-shadow: 10px 0px 10px rgba(0,0,0,0.4);
}
&#13;
<div>
  <div class="psa-circle-container"><span class="psa-circle">12</span>
    <br>CIUDADES</div>

  <div class="psa-circle-container"><span class="psa-circle">3</span>
    <br>EQUIPOS POR CIUDAD</div>

  <div class="psa-circle-container"><span class="psa-circle">18</span>
    <br>JUGADORES POR EQUIPO</div>

</div>
&#13;
&#13;
&#13;

答案 1 :(得分:5)

您可以使用box-shadow执行此操作:

.psa-circle-container + .psa-circle-container:before {
  content: "";

  position: absolute;
  top: 25%;
  right: 100%;

  width: 25%;
  height: 50%;
  border-radius: 50%;

  box-shadow: 2px 0 15px 1px rgba(0,0,0,0.7);
}

.psa-circle-container + .psa-circle-container:after {
  content: "";

  position: absolute;
  width: calc(25% + 13px);
  height: 100%;

  top: 0;
  left: calc(-25% - 13px);

  /* Background color copied from example */
  background: #59bbed;
}

这会创建两个伪元素。第一个是实际的阴影。这是通过box-shadow完成的。为了使阴影略微圆,我添加了border-radius并使元素成为椭圆。其余所有东西都放在容器之间。

第二个元素是保持椭圆形阴影看起来像一个模糊的椭圆。所有这一切都是阻挡阴影的一部分,用与背景相同的颜色覆盖阴影。这可能不是一个理想的解决方案。

下面的代码段显示了所有内容:

&#13;
&#13;
body {
  background: #59bbed;
}

.psa-circle {
    font-size: 35px;
    line-height: 70px;
    display: inline-block;
    width: 70px;
    height: 70px;
    background: white;
    border-radius: 50%;
    margin: 30px;
    box-shadow: inset 0 0 5px #000000;
    color: black;
}
.psa-circle-container {
    display: inline-block;
    text-align: center;
    color: white;
    padding: 20px;
    width: 180px;
    vertical-align: top;
    font-size: 18px;
    font-weight: bold;
    margin: 0 20px 20px;
    padding-top: 0;
    position: relative;
}

.psa-circle-container + .psa-circle-container:before {
  content: "";
  position: absolute;
  width: 25%;
  height: 50%;
  top: 25%;
  right: 100%;
  box-shadow: 2px 0 15px 1px rgba(0,0,0,0.7);
  border-radius: 50%;
}

.psa-circle-container + .psa-circle-container:after {
  content: "";
  position: absolute;
  width: calc(25% + 13px);
  height: 100%;
  top: 0;
  left: calc(-25% - 13px);
  background: #59bbed;
}
&#13;
<div>
    <div class="psa-circle-container"><span class="psa-circle">12</span><br>CIUDADES</div>

    <div class="psa-circle-container"><span class="psa-circle">3</span><br>
    EQUIPOS POR CIUDAD</div>

    <div class="psa-circle-container"><span class="psa-circle">18</span><br>
    JUGADORES POR EQUIPO</div>

</div>
&#13;
&#13;
&#13;

相关问题