【发布时间】:2021-09-17 20:15:53
【问题描述】:
我正在尝试学习 HTML/CSS 的基础知识。我了解到 :hover 在 css 中,当光标悬停在元素上时,根据编写的代码发生了一些事情。然后,您也可以使用transition 标签,使转换需要一些时间。但是,当光标离开元素时,它又回到了原来的位置,没有进行过渡,这太可怕了。这是我写的代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
.required::before {
content: '';
display:block;
width: 10px;
height: 10px;
background-color: red;
border-radius:10px;
}
.required::after {
content: '';
display:inline-block;
width: 10px;
height: 10px;
background: blue;
margin-left: -20px;
}
.required:hover::after{
transform: translateX(100px);
transition: 1s;
}
</style>
</head>
<body>
<label class = required>Name</label>
</body>
</html>
当光标悬停时,立方体以 1 秒的间隔移动。鼠标移开,它立即返回到他的第一个位置。我希望它以相同数量的类型返回位置。希望我的描述足够清楚。感谢您的帮助
【问题讨论】:
-
尝试
class="required"而不是class = required。不带引号的 HTML 会导致一些问题。