Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

center an image in a css circle

Tags:

html

css

enter image description here

This is an image in a CSS circle. I want the circle to surround the image so the image is supposed to be in the center. How can i do that?

HTML:

<div class="circletag" id="nay">
    <img src="/images/no.png">
</div>

CSS:

div.circletag {
    display: block;
    width: 40px;
    height: 40px;
    background: #E6E7ED;
    -moz-border-radius: 20px;
    -webkit-border-radius: 20px;
}
div.circletag.img {

}
like image 732
Chobeat Avatar asked Dec 12 '11 11:12

Chobeat


2 Answers

I think this is the easiest way to make an image centered within a circle

.circletag{
    width: 100px;
    height: 100px;
    padding: 20px;
    border-radius: 50%;
    background-color: #fff;
    line-height: 100px;
    text-align: center;
} 
.circletag img{
    width: 100%;
    height: auto;
    position: relative;
    top: 50%;
    transform: translate(0%, -50%);
}
like image 82
Masudur Rahman Avatar answered Oct 05 '22 10:10

Masudur Rahman


Use the image as background image.

.circletag {
    display: block;
    width: 40px;
    height: 40px;
    background: #E6E7ED;
    -moz-border-radius: 20px;
    -webkit-border-radius: 20px;
    background-image: url(no.png);
    background-position:50% 50%;
    background-repeat:no-repeat;    
}

If you don't want to have the entire outer div to be clickable, this might work:

.circletag {
    display: block;
    width: 40px;
    height: 40px;
    background: #E6E7ED;
    -moz-border-radius: 20px;
    -webkit-border-radius: 20px;    
    text-align:center;
}

.circletag img{
    margin-top:7px;
}
like image 32
Zsolt Schäfer Avatar answered Oct 05 '22 10:10

Zsolt Schäfer