有谁知道如何使用CSS实现以下效果?(我指的是每个圆圈之间的阴影)
到目前为止,我的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>
Run Code Online (Sandbox Code Playgroud)
这是我的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;
}
Run Code Online (Sandbox Code Playgroud)
完成这个:
我试图使用带有插入阴影的"psa-circle-container"但没有成功.我试过谷歌搜索阴影效果,但我没有找到类似的东西.
你可以使用伪元素 ::before
.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);
}Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
您可以使用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;
}
Run Code Online (Sandbox Code Playgroud)
这会创建两个伪元素.第一个是实际的阴影.这是通过box-shadow.为了使阴影略微圆,我添加了一个border-radius并使元素成为椭圆.其中所有其他东西都放在容器之间.
第二个元素是保持椭圆阴影看起来像一个模糊的椭圆.它是所有阻挡阴影的一部分,通过用相同的颜色作为背景覆盖它.这可能不是一个理想的解决方案.
下面的代码段显示了所有内容:
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;
}Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)