可以使用 border-radius 属性实现:

div {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #ccc;
  box-sizing: border-box;
  padding: 4px; /* 40px - 32px / 2 = 4px */
}

这里将 div 的宽高设置为 40px,并使用 border-radius 属性将其变为圆形,同时设置背景颜色为灰色。由于要让圆直径为 32px,需要在 div 内部添加一些 padding,将实际的内容区域缩小。具体来说,padding 应该为 (40px - 32px) / 2 = 4px。最后,将 box-sizing 属性设置为 border-box,确保 padding 不会影响 div 的宽高。

CSS 实现 32px 直径的圆形 div

原文地址: https://www.cveoy.top/t/topic/oAFS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录