如果我对border-radius 使用像素或em值,则边缘半径始终为圆弧或药丸形状,即使该值大于元素的最大边.
当我使用百分比时,边缘半径是椭圆形的,从元素每边的中间开始,形成椭圆形或椭圆形:


border-radius的像素值:
div {
background: teal;
border-radius: 999px;
width: 230px;
height: 100px;
padding: 40px 10px;
box-sizing: border-box;
font-family: courier;
color: #fff;
}Run Code Online (Sandbox Code Playgroud)
<div>border-radius:999px;</div>Run Code Online (Sandbox Code Playgroud)
border-radius的百分比值:
div {
background: teal;
border-radius: 50%;
width: 230px;
height: 100px;
padding:40px 10px;
box-sizing:border-box;
font-family:courier;
color:#fff;
}Run Code Online (Sandbox Code Playgroud)
<div>border-radius:50%;</div>Run Code Online (Sandbox Code Playgroud)
为什么边界半径百分比的作用方式与使用像素值或em值设置的border-radius的作用方式相同?
是否可以使用没有设定宽度或高度的边界半径制作胶囊形状?
我希望左右两侧完全圆润,而胶囊沿着它的水平长度保持笔直.将半径设置为50%似乎不会产生预期的效果.
