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" />
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.
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.
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" />
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="">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With