CSS 双边框圆形

CSS circle with double border

我刚收到 Designer 的 PSD,大部分部分都可以通过 CSS 实现,只有一点我想做,但对我来说似乎很难的是一个有 2 个边框的圆。 我可以使用 bg 图像方法,但使用 CSS3.

实现会更理想

使用 CSS 的主要原因之一是在几个不同的元素上使用了相同的边框。

您可以使用 ::before::after 伪元素来创建此形状:

.btn-holder {
  background: darkgreen;
  padding: 30px;
}

.btn {
  background: transparent;
  justify-content: center;
  align-items: center;
  position: relative;
  color: #fff;
  display: flex;
  height: 100px;
  width: 100px;
}

.btn,
.btn::after {
  border: 1px solid #fff;
  border-radius: 100%;
}

.btn::after {
  position: absolute;
  content: '';
  width: 100%;
  height: 100%;
  left: 0;
  top: -4px;
}
<div class="btn-holder">
  <button type="button" class="btn">Register</button>
</div>

你可以尝试 :after 为圆制作 2 个边框:

.green{
  width: 300px;
  height: 300px;
  background-color: green;
  display: flex;
  align-items: center;
  justify-content: center;
}

.circle {
  position: relative;
  width: 150px;
  height: 150px;
  border: 1px solid #fff;
  border-radius: 50%;
}

.circle::after {
  content: '';
  width: 150px;
  height: 150px;
  border: 1px solid #fff;
  border-radius: 50%;
  display: block;
  margin: -4px 2px;
}
<div class="green">
  <div class="circle"></div>
</div>

您可以将单个元素与 box-shadow - CSS | MDN

一起使用

button{
  position:relative;
  margin: 20px auto;
  border-radius: 50%;
  border: 2px solid transparent;
  border-bottom: none;
  border-top: none;
  width: 100px;
  height: 100px;
  color: red;
  box-shadow: -1px -1px currentcolor, 
               1px 1px currentcolor,
               
               inset -1px 1px currentcolor, 
               inset 1px -1px currentcolor;
  display: block;
  background-color: #fd999952;
  background-clip: padding-box;
  font-weight: bolder;
  outline: none;
}
<button type="button" class="btn">Register</button>