Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expand width of circle

I'm pretty new to CSS3 animations to I'd like to know you how to do the following one: I have a circe:

CSS circle

On hover, I'd like to expand the width of the circle making it into a pill shape with a transition like in this image:

CSS circle with expanded width

This is what I tried. The issue is that the circle transitions to an ellipse as the width expands :

.logo {
  background: red;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  transition: width 2s;
}

.logo:hover {
  width: 300px;
}
<div class="logo"></div>
like image 688
Rowandish Avatar asked Apr 28 '15 15:04

Rowandish


People also ask

How do you expand a circle in CSS?

If you want the circle to stretch to a pill shape, set border-radius to half the element's height instead of 50% . If the height is unknown, pick some arbitrarily large value (for example, 99em ).

How to Make a div circular?

To create a circular div in CSS, follow the same steps as above. Add a div in HTML. Then, set the width and height of the element to the same value. Finally, specify the value of the border-radius property to 50%.


1 Answers

You just need to change the border-radius value to any other unit than percentage (all units listed here). For an explanation of how this works and why you need to use these units for the desired output, see Border-radius in percentage (%) vs pixels (px).

Example with px. The circle expands to a pill shape on hover :

.logo {
  width: 100px;
  height: 100px;
  border-radius: 50px;
  background: red;
  transition: width 2s;
}
.logo:hover {
  width: 300px;
}
<div class="logo"></div>

If you don't know the height of the circle, you can set a very high value so the circle keeps its pill shape as the width expands :

.logo {
  width: 200px;
  height: 200px;
  border-radius: 999px;
  background: red;
  transition: width 2s;
}
.logo:hover {
  width: 400px;
}
<div class="logo"></div>
like image 106
web-tiki Avatar answered Oct 01 '22 02:10

web-tiki