如何用 HTML + CSS 制作一个圆形(Make a Circle)

在网页开发中,使用 CSS 创建一个圆形非常简单。你只需要一个具有相同宽度和高度的块级元素,并将 border-radius 设置为 50% 即可。

示例代码

<div class="circle"></div>

<style>
.circle {
  width: 150px;
  height: 150px;
  background-color: #4CAF50;
  border-radius: 50%;
}
</style>

通过调整 widthheight 的值,你可以控制圆形的大小;通过修改 background-color 可以改变颜色。这是前端开发中最基础也最常用的技巧之一。