记录导师讲解制作hover的一个样式效果(就是下面这样子)
然后它的原理是这样的(随便盗的图片)
代码如下!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hover</title>
<style>
body {
background-color: #e1332d;
}
.box {
/* 相对定位,自绝父相 */
position: relative;
overflow: hidden;
width: 170px;
height: 50px;
border: 1px solid #fff;
color: #fff;
text-align: center;
line-height: 50px;
}
.box::before {
content: '';
/* 绝对定位不占位置 */
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
> /* 制作高亮光线 */
> background-image: linear-gradient(
> 90deg,
> rgba(255,255,255,0),
> rgba(255,255,255,.5),
> rgba(255,255,255,0));
/* 向左侧移动自身的100%宽度,配合overflow:hidden把自己藏起来 */
/* 使盒子倾斜 */
transform: translateX(-100%) skew(-45deg);
}
.box:hover::before {
transform: translateX(100%) skew(-45deg);
transition: all .3s;
}
</style>
</head>
<body>
<div class="box">HOVER</div>
</body>
</html>
注意
盒子需要倾斜,不然看起来就是一个大白耗子窜过去
渐变两端为白色,不透明度为0