最近看到一个比较有意思的效果,就是鼠标移入后,在对应的文字下方会出现下划线的动画效果,当鼠标移除后,下划线动画会消失
下面线下划线的颜色我用的渐变写的,我想告诉大家的是他是一个背景
如下图:
代码如下:
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width initial-scale=1.0 maximum-scale=1.0 user-scalable=0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<div class="box">
<div class="box_cen">
<div class="box_img">
<img src="./images/1.jpg" alt="">
</div>
<div class="box_text">
<span>Weighing the Trade-Offs of Native vs. Cross-Platform</span>
<div>From an engineering standpoint, there are several options for building mobile applications, each with its strengths and weaknesses.</div>
<div>Weighing the Trade-Offs of Native vs. Cross-Platform </div>
</div>
</div>
</body>
<style>
*{
margin: 0;
padding: 0;
}
img{
width: 100%;
height: 100%;
}
.box{
width: 100%;
height: auto;
}
.box_cen{
width: 920px;
height: 113px;
border: 1px solid #ccc;
margin-left: 300px;
margin-top: 20px;
display: flex;
align-items: center;
justify-content: space-between;
}
.box_img{
width: 150px;
height: 95px;
background-color: pink;
}
.box_text{
width: 750px;
height: 100%;
font-size: 15px;
color: #0099FF;
margin-top: 5px;
}
.box_text span{
font-size: 26px;
background: linear-gradient(to right, red, pink) no-repeat right bottom;
background-size: 0 3px;
transition: background-size 2.5s;
padding: 0 0 4px 0;
}
.box_text span:hover{
padding: 0 0 4px 0;
font-size: 26px;
background-position-x: left;
background-size: 100% 3px ;
}
</style>
</html>
鼠标移入那个标签需要使用span,我试了好几个标签出现的效果都有问题,只有span效果没问题
以上就是鼠标移动到文字上出现下划线,并且下划线有动画效果的所有内容,感谢观看