代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
a {
position: relative;
text-decoration: none;
color: #000; /* 设置文字颜色 */
}
a::after {
content: '';
position: absolute;
left: 50%;
bottom: -2px; /* 调整下划线位置 */
width: 0;
height: 2px;
background-color: #000; /* 设置下划线颜色 */
transition: width 1s, left 1s; /* 使下划线从中间向两边延伸 */
}
a:hover::after {
width: 100%;
left: 0;
}
</style>
</head>
<body>
<a href="#">Hover over me</a>
</body>
</html>