1

我有一个有内外框阴影的圆圈,但有 1px 不需要的边框。谁能帮我理解为什么只有圈子会发生这种情况并分享解决方案。

.wrapper {
  padding: 30px;
}

.circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 16px #f9f9f9, 0 0 0 16px #f1f1f1;
  background: #32a500;
}
<div class="wrapper">
  <div class="circle"></div>
</div>

4

2 回答 2

2

我认为box-shadow: inset是搞砸了border-radius

在等待其他解决方案时,您始终可以避免使用inset并应用 a border,手动从 div 的高度和宽度中删除 32px (16px + 16px)。

.wrapper {
  padding: 30px;
}

.circle {
  border-radius: 50%;
  background: #32a500;
  box-shadow: 0px 0px 0px 16px #f1f1f1;
  border: 16px solid #f9f9f9;
  width: 88px;
  height: 88px;
}
<div class="wrapper">
  <div class="circle"></div>
</div>

于 2013-05-02T11:59:13.463 回答
1

在@Andrea Ligios 的帮助下更新了代码

.wrapper {
  padding: 30px;
}

.circle {
  border-radius: 50%;
  background: #32a500;
  box-shadow: 0px 0px 0px 16px #f1f1f1;
  border: 16px solid #f9f9f9;
  width: 120px;
  height: 120px;
  box-sizing: border-box;
}
<div class="wrapper">
  <div class="circle"></div>
</div>

于 2013-05-02T12:49:14.797 回答