HTML+CSS 鼠标悬停发光按钮

在b站上看的小视频,看着按钮悬停发光效果很好,写的描述很清楚。
效果图
在这里插入图片描述

index.html代码

<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>HTML+CSS 鼠标悬停发光</title>
		<link rel="stylesheet" href="css/index.css" />
	</head>
	<body>
		<div class="container">
			<!-- javascript:void(0)是js的关键字,可以阻止连接跳转 -->
			<a href="javascript:void(0);" style="--i: 1">点赞</a>
			<a href="javascript:void(0);" style="--i: 2">投币</a>
			<a href="javascript:void(0);" style="--i: 3">收藏</a>
			<a href="javascript:void(0);" style="--i: 4">关注</a>
			<a href="javascript:void(0);" style="--i: 5">分享</a>
		</div>
	</body>
</html>

index.css代码

* {
	/* 初始化 清除页面元素的内外边距 */
	padding: 0;
	margin: 0;
}
.container {
	/* 弹性布局 让页面元素垂直+水平居中 */
	display: flex;
	justify-content: center;
	align-items: center;
	/* 让子元素垂直排列 */
	flex-direction: column;
	/* 宽度占浏览器可视窗口总宽度 高度占浏览器可视区域总高度 */
	width: 100vm;
	height: 100vh;
	background-color: #000;
}
.container a {
	/* 相对定位 */
	position: relative;
	/* 将a这个行内元素转为块级元素不然无法设置宽和高 */
	display: block;
	width: 140px;
	height: 60px;
	/* 行高 */
	line-height: 60px;
	text-align: center;
	margin: 40px;
	color: aqua;
	font-size: 20px;
	/* 取消下划线 */
	text-decoration: none;
	/* 加一下一些过渡事件 */
	transition: all 0.3s ease-in-out;
	/* 重头戏来了,改变各个元素的颜色,一句话就能搞定 */
	/* hue-rotate是颜色滤镜 可以加不同的度数来改变颜色
  这里我们用了calc自动计算的方法,还有var函数来调用我们给每一个a设置的不同的属性值1~5,然后分别乘以60度,就能够分别得到不同的度数 */
	filter: hue-rotate(calc(var(--i) * 60deg));
}
.container a::before,
.container a::after {
	/* 将两个伪元素的相同部分写在一起 */
	content: "";
	position: absolute;
	width: 20px;
	height: 20px;
	border: 2px solid aqua;
	/* 最后的.3s是延迟时间 */
	transition: all 0.3s ease-in-out 0.3s;
}
.container a::before {
	top: 0;
	left: 0;
	/* 删除左边的伪元素的右和下边框 */
	border-right: 0;
	border-bottom: 0;
}
.container a::after {
	right: 0;
	bottom: 0;
	/* 删除右边的伪元素的上边和左边的边框 */
	border-top: 0;
	border-left: 0;
}
.container a:hover {
	background-color: aqua;
	color: #000;
	/* 加个发光效果和下面的倒影 */
	/* 模糊度加到了50px */
	box-shadow: 0 0 50px aqua;
	/* below 是下倒影 1px是倒影的元素相隔的距离 最后是个渐变的颜色 */
	-webkit-box-reflect: below 1px
		linear-gradient(transparent, rgba(0, 0, 0, 0.3));
	/* 设置一下以上属性的延迟时间 */
	transition-delay: 0.4s;
}
/* 在设置两条线的变化 总体来说四条各个方向的 只需要改变一下两个伪元素的宽度和高度 */
.container a:hover::before,
.container a:hover::after {
	width: 138px;
	height: 58px;
	transition-delay: 0s;
}

参考链接:https://gitee.com/QH_ayang/hover

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值