您可以使用
border-top-left-radius和
border-top-right-radius属性根据框的高度(和添加的边框)对框上的角进行四舍五入。
然后在框的顶部/右侧/左侧添加边框以实现效果。
干得好:
.half-circle {
width: 200px;
height: 100px; /* as the half of the width */
background-color: gold;
border-top-left-radius: 110px; /* 100px of height + 10px of border */
border-top-right-radius: 110px; /* 100px of height + 10px of border */
border: 10px solid gray;
border-bottom: 0;
}
或者,您可以添加box-sizing: border-box到框中,以计算框的宽度/高度,包括边框和填充。
.half-circle {
width: 200px;
height: 100px; /* as the half of the width */
border-top-left-radius: 100px;
border-top-right-radius: 100px;
border: 10px solid gray;
border-bottom: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
(Demo无背景颜色)