按钮悬浮效果纯html+css

本文介绍了一种使用纯CSS实现的按钮悬停效果,通过:before和:after伪元素结合过渡效果,使按钮在鼠标悬停时展现出独特的视觉变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<button class="noselect"></button>
* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

body {
	height: 100vh;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: #42378f;
	background-image: linear-gradient(315deg, #42378f 0%, #f53844 74%);
}

.noselect {
  -webkit-touch-callout: none;
    -webkit-user-select: none;
     -khtml-user-select: none;
       -moz-user-select: none;
        -ms-user-select: none;
            user-select: none;
		-webkit-tap-highlight-color: transparent;
}

button {
	width: 200px;
	height: 50px;
	cursor: pointer;
	background: none;
	border: none;
}

button:before, button:after {
	content: 'Hover!';
	letter-spacing: 4px;
	font-size: 15px;
	display: flex;
	align-items: center;
	justify-content: center;
	transform: translateY(-50%);
	position: absolute;
	z-index: -1;
	width: 200px;
	height: 50px;
	transition: 500ms;
}

button:before {
	overflow: hidden;
	background: rgba(255,255,255,0.5);
}

button:after {
	width: 0px;
	overflow: hidden;
	border-bottom: 2px solid rgba(255,255,255,0.5);
	border-top: 2px solid rgba(255,255,255,0.5);
	transform: translateY(-50%) translateX(100px);
	color: rgba(255,255,255,0.5);
}

button:hover:before {
	width: 0px;
	transform: translateY(-50%) translateX(100px);
}

button:hover:after {
	width: 200px;
	transform: translateY(-50%) translateX(0px);
}

button:focus {
	outline: none;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值