用css让头像变圆且鼠标悬停在图片上时会发光

代码如下:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
.img-circle {
	-moz-border-radius: 50%;
	-webkit-border-radius: 50%;
	border-radius: 50%;
}

.img-circle:hover {
	-moz-box-shadow: 0px 0px 25px rgba(0, 255, 178, 1);
	-webkit-box-shadow: 0px 0px 25px rgba(0, 255, 178, 1);
	box-shadow: 0px 0px 25px rgba(0, 255, 178, 1);
	cursor: pointer;
}
</style>
<title>Insert title here</title>
</head>
<body>
	<img class="img-circle" alt="我是头像" src="images/default_head.jpg">
</body>
</html>
鼠标未移动在头像上时

鼠标移动到头像上时

如果头像太大, 可以通过样式来限制, 可以在<img>里添加属性style="width: 100px; height: 100px;"
<img class="img-circle" alt="我是头像" src="images/default_head.jpg" style="width: 100px; height: 100px;">
效果如下:

另外, z-index值一定要比周围元素的要高, 否则有可能出现头像被其他元素遮挡住, 可以用.img-circle里加上z-index: 99;
如果还想在头像外加上一层border像光晕也是可以的,为突出效果, 我设置body的背景颜色 
完整代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
body {
	background-color: #0D5193;
}
.img-circle {
	z-index: 99;
	
	-moz-border-radius: 50%;
	-webkit-border-radius: 50%;
	border-radius: 50%;
	
	border: 8px solid;
	border-color: rgba(255, 255, 255, 0.2);
}

.img-circle:hover {
	-moz-box-shadow: 0px 0px 25px rgba(0, 255, 178, 1);
	-webkit-box-shadow: 0px 0px 25px rgba(0, 255, 178, 1);
	box-shadow: 0px 0px 25px rgba(0, 255, 178, 1);
	cursor: pointer;
}
</style>
<title>Insert title here</title>
</head>
<body>
	<img class="img-circle" alt="我是头像" src="images/default_head.jpg" style="width: 100px; height: 100px;">
</body>
</html>
 
 
效果如下:
 
OK, Enjoy it!!!  例子代码下载
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值