gpt4 book ai didi

html - 无法使用CSS动画垂直翻转导航栏菜单文本

转载 作者:行者123 更新时间:2023-12-04 17:12:55 26 4
gpt4 key购买 nike

我正在尝试创建导航栏菜单,其中的文本在悬停时会翻转。

这是我到目前为止尝试的代码,并嵌入了显示我试图实现的最终结果的视频。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
border: 0;
vertical-align: baseline;
background: transparent;
font-weight: normal;
text-decoration: none;
outline: none;
box-sizing: border-box;
}
.wrapper {
width: 90%;
margin: 0 auto;
max-width:1100px;
}
header {
height: 100px;
padding: 20px 0;
}
header nav {}
header nav ul {
list-style: none;
display: flex;
justify-content: space-between;
}
header nav ul li {
font-size: 23px;
position: relative;
}
header nav ul li a {
position: absolute;
}
header nav ul li a:hover {
animation: flip 2s ease infinite;
}
div.video iframe {
margin-top: 30px;
}
@keyframes flip {
0% {
top: 0;
}
25% {
top: -50px;
}
50% {
top: -100px;
}
75% {
top: -150px;
}
100% {
top: 0;
}
}
</style>
</head>
<body>
<header>
<nav>
<section class="wrapper">
<ul>
<li><a href="#">About</a></li>
<li><a href="#">Project</a></li>
<li><a href="#">Resume</a></li>
</ul>
</section>
</nav>
</header>
<div class="video">
<section class="wrapper">
<iframe width="560" height="315" src="https://www.youtube.com/embed/WeUfsRce9_M" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<h3>Video link is given if iframe is note suported by stackoverflow code snippet poster</h3>
<a href="https://www.youtube.com/embed/WeUfsRce9_M" target="_blank" >Video link</a>
</section>
</div>
</body>
</html>

我想不出一种方法来为当我们悬停并从底部返回到起始位置时向上移动的文本设置动画。

最佳答案

您需要为此使用::after::before 选择器。请注意,您需要为所有链接添加data-text属性(以链接名称作为值)。

* {
margin: 0;
padding: 0;
border: 0;
vertical-align: baseline;
background: transparent;
font-weight: normal;
text-decoration: none;
outline: none;
box-sizing: border-box;
}

.wrapper {
width: 90%;
margin: 0 auto;
max-width: 1100px;
}

header {
height: 100px;
padding: 20px 0;
}

header nav {}

header nav ul {
list-style: none;
display: flex;
justify-content: space-between;
}

header nav ul li {
font-size: 23px;
position: relative;
}

header nav ul li a {
position: absolute;
height: 1.3em;
display: flex;
flex-direction: column;
overflow: hidden;
}

header nav ul li a::after {
content: attr(data-text);
color: red;
transition: transform 0.3s;
}

header nav ul li a::before {
content: attr(data-text);
color: blue;
transition: transform 0.3s;
}

header nav ul li a:hover::before {
transform: translateY(-1.15em);
}

header nav ul li a:hover::after {
transform: translateY(-1.15em);
}

div.video iframe {
margin-top: 30px;
}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>
<header>
<nav>
<section class="wrapper">
<ul>
<li>
<a data-text="About" href=""></a>
</li>
<li>
<a data-text="Project" href=""></a>
</li>
<li>
<a data-text="Resume" href=""></a>
</li>
</ul>
</section>
</nav>
</header>
<div class="video">
<section class="wrapper">
<iframe width="560" height="315" src="https://www.youtube.com/embed/WeUfsRce9_M" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<h3>Video link is given if iframe is note suported by stackoverflow code snpite poster</h3>
<a href="https://www.youtube.com/embed/WeUfsRce9_M" target="_blank">Vide link</a>
</section>
</div>
</body>

</html>

关于html - 无法使用CSS动画垂直翻转导航栏菜单文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69142260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com