css3 background size background-size attribute realizes the animation effect of mouse moving into text underline

Recently I saw a very interesting animation on a page. When the mouse is moved in, an underline animation will appear under the corresponding text. When the mouse is removed, the underline animation will disappear, so I thought about how to implement this animation. Effect.

The first idea was to do it through with, but there would be a problem, that is, the text is not fixed, and the length and height may change. This was not possible, so I thought about using background size control.

The specific effects are as follows:

code show as below:

<!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>3D地图</title>
<style>
body,html{ margin:0;padding:0;}
.box{
  width: 250px;
  margin: 100px auto;
}
.box span {
  font-size: 26px;
  background: linear-gradient(to right, red, yellow) no-repeat right bottom;
  background-size: 0 3px;
  transition: background-size 1s;
}
.box span:hover {
  font-size: 26px;
  background-position-x: left;
  background-size: 100% 3px ;
}
</style>

</head>
<body>
<div class="box">
<span>你好啊哈哈哈哈哈哈你好撒护肤撒护肤哈哈哈哈哈</span>
</body>
</html>

Guess you like

Origin blog.csdn.net/CodingNoob/article/details/129729840
Recommended