css 实现圆形头像

1、方法一

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

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

相应的css为

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

boder-radius为图片宽度的一半

2、方法二

通过背景图设置

<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;

显示效果为

 

  

posted @ 2018-07-13 17:16  慵懒的小猪  阅读(12532)  评论(0编辑  收藏  举报