css 实现圆形头像 转

转自:https://www.cnblogs.com/lhyhappy365/p/9306138.html

1、方法一

直接设置img为圆形,这种情况下如果图片不是正方形,图片会被拉伸

1
<img class="circleImg" src="../img/photo/img.jpg"  />

相应的css为

1
2
3
4
5
.circleImg{
  border-radius: 30px;
  width:60px;
  height:60px;
}

boder-radius为图片宽度的一半

2、方法二

通过背景图设置

1
<div class="bgImg"></div>

相应的css为

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

拖图片不是方形,则按照宽度等比例显示,则background-size设置为图片宽度,高度为auto,若需要按照高度等比例显示,则background-size:auto 60px;

点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注