Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force image tag to be perfect circle

Tags:

html

css

Is this possible? I want an image to be a perfect circle no matter if the image is not a perfect square ie: 100px x 100px.

.circle {
 border-radius: 50%;
 height: 100px;
 width: 100px;
}

With that code, if the image is 200x150, the img tag would be in the shape of an oval. Could I get a perfect circle no matter the image size?

<img class="circle" src="/link/to/img.jpg" height="80" width="80" />
like image 936
Sylar Avatar asked Jun 20 '16 10:06

Sylar


People also ask

How do I make a div A Perfect circle?

So if you want perfect circles what you have to do is to first have a square div, it has to be a square, then you go to borders and select the radius to 50%. That should make your div into a perfect circle.

How do you make an image completely Round in CSS?

The way to make image rounded or circular Style img element with border-radius: 50% . Set width and height to the same value, say, width:100px and height:100px . That's all.


2 Answers

I know this question is a bit old but there is actually a way to achieve what is asked without using a wrapper div:

.circle {
 border-radius: 50%;
 object-fit: cover;
}

<img class="circle" src="/link/to/img.jpg" height="80" width="80" />
like image 199
Carlos Alves Jorge Avatar answered Oct 18 '22 23:10

Carlos Alves Jorge


No, you need to wrap the image in a div, apply the rounding to that and hide any overflow.

Here I have also centered the image with flexbox but that's not a requirement.

.circle {
 border-radius: 50%;
 height: 100px;
 width: 100px;
 overflow: hidden;
 display: flex;
 justify-content: center;
 align-items: center;
}
<div class="circle">
  <img src="http://www.fillmurray.com/460/300" alt="">
</div>

<h2> Actual Image</h2>

  <img src="http://www.fillmurray.com/460/300" alt="">
like image 41
Paulie_D Avatar answered Oct 18 '22 22:10

Paulie_D