CSS边框带有圆角圆圈

huangapple go评论54阅读模式
英文:

CSS border with circles in corners

问题

这种边框效果是否可以仅使用CSS创建?

英文:

Is it possible to create this sort of border effect in css only?

CSS边框带有圆角圆圈

答案1

得分: 1

以下是您提供的内容的中文翻译:

.box {
  --b: 5px; /* 边框厚度 */

  width: 200px;
  aspect-ratio: 1;
  margin: 20px;
  border-image: 
   radial-gradient(#000 50%,#fff 52% 71%,#0000 72%) 
   100%/40px/18px;
  background: 
   conic-gradient(from 90deg at var(--b) var(--b),#0000 25%,#000 0)
   0 0/calc(100% - var(--b)) calc(100% - var(--b))
}
<div class="box"></div>
英文:

A quick solution using border-image (for the circles) and conic-gradient (for the border)

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.box {
  --b: 5px; /* border thickness */

  width: 200px;
  aspect-ratio: 1;
  margin: 20px;
  border-image: 
   radial-gradient(#000 50%,#fff 52% 71%,#0000 72%) 
   100%/40px/18px;
  background: 
   conic-gradient(from 90deg at var(--b) var(--b),#0000 25%,#000 0)
   0 0/calc(100% - var(--b)) calc(100% - var(--b))
    
}

<!-- language: lang-html -->

&lt;div class=&quot;box&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年7月13日 15:43:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76677017.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定