Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fit img into div circle ?

I'm beginner in HTML/CSS.

I've created some div that looks like a circle. I want to put facebook image into that circle, but as a circle logo.

Click to see IMAGE

HTML

<div class="social" id="social1"> Facebook
  <a href="www.facebook.com">
    <img src="https://www.facebook.com/images/fb_icon_325x325.png" width="106" height="106"/> 
     </a>
</div>

CSS

div {
     display: inline-block;
     margin-left: 55px;
     height: 100px;
     width: 100px;
     border-radius: 100%;
     border: 2px solid black;
     text-align:center;
   }

img {
     width: 100%;
     height : 100%;
     object-fit: contain;
    }

How to fit img into div circle ?

like image 445
Orkun Oz Avatar asked Jun 02 '16 19:06

Orkun Oz


People also ask

How do I put an image in a circle in HTML?

Complete HTML/CSS Course 2022 To display an image inside SVG circle, use the <circle> element and set the clipping path. The <clipPath> element is used to define a clipping path. Image in SVG is set using the <image> element.

Can I put an image in a div?

1) Create a DIV tag with a unique ID; 2) Place the image into a background:url style element of a DIV tag; 3) Set the height and width properties of the DIV tag to that of the selected image.

How do I make a perfect circle div?

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%.

How do I make an image border round in CSS?

The border-radius CSS property is what adds the rounded corners. You can experiment with different values to get it the way you like. border-radius: 75px; If you want it to be a circle, add border-radius: 50%; .


2 Answers

.social .facebook {
  display: inline-block;
  width: 100px;
  height: 100px;
  background: url(https://www.facebook.com/images/fb_icon_325x325.png);
  background-position: 50% 50%;
  background-size: cover;
  border-radius: 50%;
}
<div class="social" id="social1">
  <a class="facebook" href="https://www.facebook.com/"></a>
</div>
like image 110
Shanshan Bi Avatar answered Nov 15 '22 02:11

Shanshan Bi


Basically there are two ways to achieve this.

  1. You could add border-radius: 50%; to the img element.
  2. You could add overflow: hidden; to the div element.

Both will work. You should remove the "Facebook" string to get proper positioning of the image.

like image 25
Mark Langer Avatar answered Nov 15 '22 02:11

Mark Langer