简体   繁体   English

我可以使用 CSS border-radius 属性制作椭圆吗?

[英]Can I make an ellipse using the CSS border-radius property?

I'm trying to make a rectangular image (headshot)我正在尝试制作一个矩形图像(爆头)

width: 200px;   
height: 280px; 

display as an ellipse.显示为椭圆。

I can't seem to stop it trying to make a circle, or forming points at top and bottom, while the sides are still flat.我似乎无法阻止它试图制作一个圆圈,或者在顶部和底部形成点,而两侧仍然是平的。

Any help appreciated!任何帮助表示赞赏!

As per the specification , the individual border-radius properties accept a second value which if not specified defaults to whatever the first value is.根据规范,各个border-radius属性接受第二个值,如果未指定,则默认为第一个值。

3.3 The 'border-radius' properties 3.3 'border-radius'属性

The two length values of the 'border-radius' properties define the radii of a quarter ellipse that defines the shape of the corner (see the diagram below). 'border-radius' 属性的两个长度值定义了定义角形状的四分之一椭圆的半径(见下图)。 The first value is the horizontal radius (or vertical if the 'writing-mode' is vertical).第一个值是水平半径(如果 'writing-mode' 是垂直的,则是垂直的)。 If the second length is omitted it is equal to the first (and the corner is thus a quarter circle).如果省略第二个长度,则它等于第一个(因此角是四分之一圆)。 If either length is zero, the corner is square, not rounded.如果任一长度为零,则角为方形,而不是圆角。 The border radius also causes the element's background to be rounded (even if the border is 'none').边框半径也会使元素的背景变圆(即使边框为“无”)。 Negative values are not allowed.不允许使用负值。

来自规范的图像

You can use this to specify exactly where you want the radius to occur:您可以使用它来准确指定您希望半径出现的位置:

 div { background: red; width: 200px; height: 280px; border-bottom-left-radius: 50% 25%; border-bottom-right-radius: 50% 25%; border-top-left-radius: 50% 25%; border-top-right-radius: 50% 25%; }
 <div></div>

An ellipse would use 100% for either the first or second value, but a value less than 100% for the other:椭圆将100%用于第一个或第二个值,但另一个值小于100%

 div { background: red; width: 200px; height: 280px; border-bottom-left-radius: 25% 100%; border-bottom-right-radius: 25% 100%; border-top-left-radius: 25% 100%; border-top-right-radius: 25% 100%; }
 <div></div>

Have you really tryed something ??你真的尝试过吗??

 #test { width: 200px; height: 280px; border: 1px solid; border-radius: 50%; }
 <div id='test'></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM