`superellipse()` CSS function
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{SeeCompatTable}}
The **superellipse()** CSS function defines the curvature of an ellipse, and is used to specify corner shapes either directly, or via {{cssxref("<corner-shape-value>")}} keywords.
Syntax
superellipse(infinity)
superellipse(4)
superellipse(1.7)
superellipse(0)
superellipse(-2.8)
superellipse(-3)
superellipse(-infinity)Parameters
- {{cssxref("<number>")}}
- : A number in the range of
-infinitytoinfinity, inclusive.
Return value
A superellipse shape.
Description
The superellipse() function returns a superellipse shape, which is used to specify {{cssxref("corner-shape")}} values. A superellipse is a closed curve symmetric shape between a rectangle and an ellipse. It resembles an ellipse that retains the geometric features of its two axes.
The superellipse shape is calculated using a modified version of an ellipse. The following equation defines an ellipse centered at the origin:
<math display="block"> <mfrac> <msup> <mi>x</mi> <mn>2</mn> </msup> <msup> <mi>a</mi> <mn>2</mn> </msup> </mfrac> <mo>+</mo> <mfrac> <msup> <mi>y</mi> <mn>2</mn> </msup> <msup> <mi>b</mi> <mn>2</mn> </msup> </mfrac> <mo>=</mo> <mn>1</mn> </math>
The a and b variables refer to the radii of the ellipse, while the x and y coordinates are points on the ellipse's circumference.
A circle is an ellipse where the radii, the a and b in the previous equation, are the same length. With a and b both equal to r, the equation for a circle can be written as:
<math display="block"> <mrow> <msup> <mi>x</mi> <mn>2</mn> </msup> <mo>+</mo> <msup> <mi>y</mi> <mn>2</mn> </msup> <mo>=</mo> <msup> <mi>r</mi> <mn>2</mn> </msup> </mrow> </math>
In this equation, the x and y are coordinates of points on the circle's circumference, and the r is the radius of the circle, with the center of the circle being (0, 0). The ellipse is produced by scaling a circle shape along the x and/or y axis.
A superellipse shape is created by replacing the 2 exponent in each case with 2<sup>K</sup>, K being the argument passed to the superellipse() function, which modifies the curvature of the ellipse:
<math display="block"> <mrow> <msup> <mi>x</mi> <msup> <mn>2</mn> <mi>K</mi> </msup> </msup> <mo>+</mo> <msup> <mi>y</mi> <msup> <mn>2</mn> <mi>K</mi> </msup> </msup> <mo>=</mo> <mn>1</mn> </mrow> </math>
The following diagram illustrates different superellipse() values for the top right corner of a container: infinity, 1, 0, -1, and -infinity:
Line diagram illustrating the ellipses created using different K values, as described subsequently
- A
Kvalue of0creates a straight line. This value can be used to create beveled corners and corresponds to the {{cssxref("<corner-shape-value>")}}bevelkeyword. - A
Kvalue of1creates an ordinary ellipse, corresponding to theroundkeyword. - A
Kvalue of>1makes the ellipse shape more square;2corresponds to thesquirclekeyword. - A
Kvalue ofinfinitycreates a perfect square (corresponding to thesquarekeyword), althoughKvalues of10or more are virtually indistinguishable from a square. - Negative
Kvalues result in a concave curve, resulting in corner shapes that are curved inward, or "scooped out". AKvalue of-1corresponds to thescoopkeyword and-infinitycorresponds to thenotchkeyword.
A negative or positive superellipse would appear symmetrical to a superellipse with its inverse value.
توجه: For any K parameter value passed, the superellipse() function's return value will always be the same for that K value. When that value is applied to two elements, the appearance of the corner shape may differ if the box size or {{cssxref("border-radius")}} values differ.
Formal syntax
{{CSSSyntax}}
Examples
superellipse() value comparison
In this example, two [<input type="range">](/en-US/docs/Web/HTML/Reference/Elements/input/range) sliders allow you to cycle through many different corner-shape superellipse() values and {{cssxref("border-radius")}} values enabling you to compare the effects of each on a container. The code is hidden for brevity, but the full explanation of the superellipse value comparison is provided on the {{cssxref("corner-shape")}} reference page.
{{EmbedLiveSample("value-comparison", "100%", "300")}}
توجه: See also the [<corner-shape-value> value comparison](/en-US/docs/Web/CSS/Reference/Values/corner-shape-value#corner-shape-value_value_comparison) example.
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- {{cssxref("corner-shape")}}
- {{cssxref("<corner-shape-value>")}}
- CSS borders and box decorations module