Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does CSS border-radius x y exists?

Tags:

css

Let's say we have simple div and his width != height.

<div id="test"></div>

and css looks like:

#test {
    width: 200px;
    height: 50px;
    border-radius: 30%;
    border: 5px solid black;
}

enter image description here

The border-radius in percentage makes longer side more curved. This value in px would make border equally curved:

#test{
    border-radius: 30px;
}

enter image description here

My question is, is there a way (using CSS) to manipulate this proportion in px (independent from changing div size) and make for example shorter side of div more curved? Or it's only achievable via canvas.

like image 959
Zydnar Avatar asked Nov 11 '16 11:11

Zydnar


People also ask

Can CSS outline have a radius?

The outline-radius property is used to specify the radius of an outline. It is used to give rounded corners to outlines. This property can only be used in Firefox2-87 (till march 2021) and from Firefox 88, outline-property follows the shape created by border-radius automatically, so this property is no longer needed.

Why border radius is not working?

If there are contents within the div that has the curved corners, you have to set overflow: hidden because otherwise the child div's overflow can give the impression that the border-radius isn't working.

Which CSS type is used to set the border radius?

The border-radius CSS property rounds the corners of an element's outer border edge. You can set a single radius to make circular corners, or two radii to make elliptical corners.

What is the difference between border and border radius?

The only difference between them is the right button has a radius of 5px applied. As with borders, radius allows you to set different properties for each side of the element using the toggle controls.


2 Answers

Writing this question I found the answer: CSS PIE support

It is possible by using slash between values:

border-radius: 10px / 30px;

enter image description here

like image 84
Zydnar Avatar answered Oct 19 '22 02:10

Zydnar


You can use two values with a slash in between if you want all rounded corners look the same, or you can use selectors for the single corners and use two values without a slash to get independent results for each corner, like border-top-left-radius: 45px 80px;

Here are three examples (I added a symmetric one, similar to the one in your question):

.x {
  width: 300px;
  height: 200px;
  border: 2px solid green;
  border-radius: 45px / 80px;
}
.y {
  width: 300px;
  height: 200px;
  margin-top: 30px;
  border: 2px solid red;
  border-top-left-radius: 45px 80px;
  border-top-right-radius: 125px 60px;
}
.z {
  width: 300px;
  height: 100px;
  margin-top: 30px;
  border: 2px solid blue;
  border-top-left-radius: 80px 65px;
  border-bottom-left-radius: 80px 65px;
  border-top-right-radius: 80px 65px;
  border-bottom-right-radius: 80px 65px;
}
<div class="x"></div>
<div class="y"></div>
<div class="z"></div>
like image 34
Johannes Avatar answered Oct 19 '22 03:10

Johannes