How to implement a round avatar in css

王林
Release: 2020-11-18 10:59:28
Original
3889 people have browsed it

How to implement a circular avatar in css: You can directly set the img to be circular, such as [border-radius: 30px;]. It should be noted that if the image is not square using this method, the image will be stretched.

How to implement a round avatar in css

can be achieved in the following two ways:

Method 1: Directly set the img to a circle. In this case, if the picture is not Square, the image will be stretched

(Learning video sharing: css video tutorial)

<img  class="circleImg" src="../img/photo/img.jpg"  / alt="How to implement a round avatar in css" >
Copy after login

The corresponding css is:

.circleImg{
  border-radius: 30px;
  width:60px;
  height:60px;
}
Copy after login

boder-radius is half the width of the image.

Method 2: Set through the background image

<div class="bgImg"></div>
Copy after login

The corresponding css is:

.bgImg{ 
  border-radius: 30px;
  width:60px;
  height:60px; 
  background: url("../img/photo/img.jpg") no-repeat center;
  background-size:60px;
}
Copy after login

If the dragged image is not square, it will be displayed in proportion to the width, then the background-size is set to The image width and height are auto. If it needs to be displayed in proportion to the height, then background-size:auto 60px;.

Achievement effect:

How to implement a round avatar in css

Related recommendations: CSS tutorial

The above is the detailed content of How to implement a round avatar in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!