您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

CSS从矩形切出圆形

CSS从矩形切出圆形

您可以使用单个元素(加上伪元素)来完成此操作,radial-gradient而伪元素会创建圆,而父元素将背景用作背景。

div:before {  /* creates the red circle */

  position: absolute;

  content: '';

  width: 90px;

  height: 90px;

  top: -75px;  /* top = -75px, radius = 45px, so circle's center point is at -30px */

  left: calc(50% - 45px);

  background-color: red;

  border-radius: 50%;

}

div {

  position: relative;

  margin: 100px auto 0 auto;

  width: 90%;

  height: 150px;

  border-radius: 6px;



  /* only the below creates the transparent gap and the fill */

  background: radial-gradient(50px 50px at 50% -30px, rgba(0, 0, 0, 0) 49.5px, rgba(0, 0, 0, .8) 50.5px);  /* use same center point as with concentric circles but larger radius */

}



/* just for demo */



body,

html {

  font-size: 18px;

}

body {

  background-image: radial-gradient(circle, #3F9CBA 0%, #153346 100%);

}


<div></div>
CSS 2022/1/1 18:22:21 有392人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶