无法使 CSS 悬停动画正常工作
Unable to get the CSS hover animation to work
我正在尝试使用变换和过渡为这些按钮创建悬停状态,但它不起作用。是不是因为我已经有了让按钮出现的动画?我没有正确选择元素吗?我究竟做错了什么?
.hero-content {
text-align: center;
margin: 20% auto;
}
.hero-content li {
display: inline-block;
}
.hero-content a {
display: block;
width: 200px;
background-color: red;
margin-right: 20px;
text-align: center;
border-radius: 5px;
transition: .5s;
}
.hero-content a {
text-decoration: none;
}
.hero-content span {
display: inline-block;
margin: 40% 0;
font-family: Sans-Serif;
font-size: 1.3em;
font-weight: 900;
color: #fff;
}
.feat-btn {
animation-name: feat-fly;
animation-duration: 1s;
animation-fill-mode: both;
animation-timing-function: cubic-bezier(0, 0, .19, 1);
}
.box-one {
animation-delay: 1s;
}
.box-two {
animation-delay: 1.25s;
}
.box-three {
animation-delay: 1.5s;
}
.box-four {
animation-delay: 1.75s;
}
@keyframes feat-fly {
from {
transform: translateY(800px)
}
to {
transform: translateY(0)
}
}
.hero-content a:hover {
transform: translateY(-20px);
}
<ul class="hero-content">
<li>
<a href="#" class="feat-btn box-one">
<span>Web & App</span>
</a>
</li>
<li>
<a href="#" class="feat-btn box-two">
<span>Design</span>
</a>
</li>
<li>
<a href="#" class="feat-btn box-three">
<span>Film & Video</span>
</a>
</li>
<li>
<a href="#" class="feat-btn box-four">
<span>Marketing</span>
</a>
</li>
</ul>
也许我什至可以清理一下我的 CSS。我不确定可能不会。我宁愿保持大部分不变,仍然能够解决我面临的问题,但欢迎提出任何建议,但我最想解决的是我上面描述的 hove 问题。
提前致谢!
如果您想将鼠标悬停在文本上,请将鼠标悬停在文本所在的范围内。如果您想将悬停添加到红色框,请将悬停 CSS 设置为 .hero-content li: hover
。此外,我还添加了平滑过渡。
如果有疑问,请在评论中告诉我。
.hero-content {
text-align: center;
margin: 20% auto;
}
.hero-content li {
display: inline-block;
margin-bottom:20px;
}
.hero-content a {
display: block;
width: 200px;
background-color: red;
margin-right: 20px;
text-align: center;
border-radius: 5px;
transition:.5s;
}
.hero-content a {
text-decoration: none;
}
.hero-content span {
display: inline-block;
margin: 40% 0;
font-family: Sans-Serif;
font-size: 1.3em;
font-weight: 900;
color: #fff;
transition: all 0.3s ease;
}
.feat-btn {
animation-name: feat-fly;
animation-duration: 1s;
animation-fill-mode: both;
animation-timing-function: cubic-bezier(0,0,.19,1);
}
.box-one {
animation-delay: 1s;
}
.box-two {
animation-delay: 1.25s;
}
.box-three {
animation-delay: 1.5s;
}
.box-four {
animation-delay: 1.75s;
}
@keyframes feat-fly {
from{ transform: translateY(800px)}
to{ transform: translateY(0)}
}
.hero-content a span:hover {
transform: translateY(-20px);
transition: all 0.3s ease;
}
<ul class="hero-content">
<li><a href="#" class="feat-btn box-one">
<span>Web & App</span>
</a></li>
<li><a href="#" class="feat-btn box-two">
<span>Design</span>
</a></li>
<li><a href="#" class="feat-btn box-three">
<span>Film & Video</span>
</a></li>
<li><a href="#" class="feat-btn box-four">
<span>Marketing</span>
</a></li>
</ul>
你在找这个吗?
.hero-content {
text-align: center;
margin: 20% auto;
}
.hero-content li {
display: inline-block;
}
.hero-content a {
display: block;
width: 200px;
background-color: red;
margin-right: 20px;
text-align: center;
border-radius: 5px;
transition:.5s;
}
.hero-content a {
text-decoration: none;
}
.hero-content span {
display: inline-block;
margin: 40% 0;
font-family: Sans-Serif;
font-size: 1.3em;
font-weight: 900;
color: #fff;
}
.feat-btn {
animation-name: feat-fly;
animation-duration: 1s;
animation-fill-mode: both;
animation-timing-function: cubic-bezier(0,0,.19,1);
}
.box-one {
animation-delay: 1s;
}
.box-two {
animation-delay: 1.25s;
}
.box-three {
animation-delay: 1.5s;
}
.box-four {
animation-delay: 1.75s;
}
@keyframes feat-fly {
from{ transform: translateY(800px)}
to{ transform: translateY(0)}
}
.hero-content li:hover {
transform: translateY(-20px);
transition: 1s;
}
<ul class="hero-content">
<li><a href="#" class="feat-btn box-one">
<span>Web & App</span>
</a></li>
<li><a href="#" class="feat-btn box-two">
<span>Design</span>
</a></li>
<li><a href="#" class="feat-btn box-three">
<span>Film & Video</span>
</a></li>
<li><a href="#" class="feat-btn box-four">
<span>Marketing</span>
</a></li>
</ul>
我正在尝试使用变换和过渡为这些按钮创建悬停状态,但它不起作用。是不是因为我已经有了让按钮出现的动画?我没有正确选择元素吗?我究竟做错了什么?
.hero-content {
text-align: center;
margin: 20% auto;
}
.hero-content li {
display: inline-block;
}
.hero-content a {
display: block;
width: 200px;
background-color: red;
margin-right: 20px;
text-align: center;
border-radius: 5px;
transition: .5s;
}
.hero-content a {
text-decoration: none;
}
.hero-content span {
display: inline-block;
margin: 40% 0;
font-family: Sans-Serif;
font-size: 1.3em;
font-weight: 900;
color: #fff;
}
.feat-btn {
animation-name: feat-fly;
animation-duration: 1s;
animation-fill-mode: both;
animation-timing-function: cubic-bezier(0, 0, .19, 1);
}
.box-one {
animation-delay: 1s;
}
.box-two {
animation-delay: 1.25s;
}
.box-three {
animation-delay: 1.5s;
}
.box-four {
animation-delay: 1.75s;
}
@keyframes feat-fly {
from {
transform: translateY(800px)
}
to {
transform: translateY(0)
}
}
.hero-content a:hover {
transform: translateY(-20px);
}
<ul class="hero-content">
<li>
<a href="#" class="feat-btn box-one">
<span>Web & App</span>
</a>
</li>
<li>
<a href="#" class="feat-btn box-two">
<span>Design</span>
</a>
</li>
<li>
<a href="#" class="feat-btn box-three">
<span>Film & Video</span>
</a>
</li>
<li>
<a href="#" class="feat-btn box-four">
<span>Marketing</span>
</a>
</li>
</ul>
也许我什至可以清理一下我的 CSS。我不确定可能不会。我宁愿保持大部分不变,仍然能够解决我面临的问题,但欢迎提出任何建议,但我最想解决的是我上面描述的 hove 问题。
提前致谢!
如果您想将鼠标悬停在文本上,请将鼠标悬停在文本所在的范围内。如果您想将悬停添加到红色框,请将悬停 CSS 设置为 .hero-content li: hover
。此外,我还添加了平滑过渡。
如果有疑问,请在评论中告诉我。
.hero-content {
text-align: center;
margin: 20% auto;
}
.hero-content li {
display: inline-block;
margin-bottom:20px;
}
.hero-content a {
display: block;
width: 200px;
background-color: red;
margin-right: 20px;
text-align: center;
border-radius: 5px;
transition:.5s;
}
.hero-content a {
text-decoration: none;
}
.hero-content span {
display: inline-block;
margin: 40% 0;
font-family: Sans-Serif;
font-size: 1.3em;
font-weight: 900;
color: #fff;
transition: all 0.3s ease;
}
.feat-btn {
animation-name: feat-fly;
animation-duration: 1s;
animation-fill-mode: both;
animation-timing-function: cubic-bezier(0,0,.19,1);
}
.box-one {
animation-delay: 1s;
}
.box-two {
animation-delay: 1.25s;
}
.box-three {
animation-delay: 1.5s;
}
.box-four {
animation-delay: 1.75s;
}
@keyframes feat-fly {
from{ transform: translateY(800px)}
to{ transform: translateY(0)}
}
.hero-content a span:hover {
transform: translateY(-20px);
transition: all 0.3s ease;
}
<ul class="hero-content">
<li><a href="#" class="feat-btn box-one">
<span>Web & App</span>
</a></li>
<li><a href="#" class="feat-btn box-two">
<span>Design</span>
</a></li>
<li><a href="#" class="feat-btn box-three">
<span>Film & Video</span>
</a></li>
<li><a href="#" class="feat-btn box-four">
<span>Marketing</span>
</a></li>
</ul>
你在找这个吗?
.hero-content {
text-align: center;
margin: 20% auto;
}
.hero-content li {
display: inline-block;
}
.hero-content a {
display: block;
width: 200px;
background-color: red;
margin-right: 20px;
text-align: center;
border-radius: 5px;
transition:.5s;
}
.hero-content a {
text-decoration: none;
}
.hero-content span {
display: inline-block;
margin: 40% 0;
font-family: Sans-Serif;
font-size: 1.3em;
font-weight: 900;
color: #fff;
}
.feat-btn {
animation-name: feat-fly;
animation-duration: 1s;
animation-fill-mode: both;
animation-timing-function: cubic-bezier(0,0,.19,1);
}
.box-one {
animation-delay: 1s;
}
.box-two {
animation-delay: 1.25s;
}
.box-three {
animation-delay: 1.5s;
}
.box-four {
animation-delay: 1.75s;
}
@keyframes feat-fly {
from{ transform: translateY(800px)}
to{ transform: translateY(0)}
}
.hero-content li:hover {
transform: translateY(-20px);
transition: 1s;
}
<ul class="hero-content">
<li><a href="#" class="feat-btn box-one">
<span>Web & App</span>
</a></li>
<li><a href="#" class="feat-btn box-two">
<span>Design</span>
</a></li>
<li><a href="#" class="feat-btn box-three">
<span>Film & Video</span>
</a></li>
<li><a href="#" class="feat-btn box-four">
<span>Marketing</span>
</a></li>
</ul>