gpt4 book ai didi

html - 在我的按钮中添加 CSS 过渡

转载 作者:行者123 更新时间:2023-11-28 15:20:30 25 4
gpt4 key购买 nike

我想在我的按钮内部应用一个过渡来实现这样的效果:我想将里面的字母向左移动,并且当我们选择按钮时图标出现并向左移动。

转换前:
enter image description here

转换后:
enter image description here

我尝试了以下方法,但它不起作用!
出了什么问题?

.button.button-reveal span {
-webkit-transition: left 0.3s ease, right 0.3s ease;
-o-transition: left 0.3s ease, right 0.3s ease;
transition: left 0.3s ease, right 0.3s ease;
}

.button.button-reveal:hover span {
opacity: 1;
}

.button {
display: inline-block;
//position: relative;
cursor: pointer;
outline: none;
white-space: nowrap;
margin: 5px;
padding: 0 22px;
font-size: 14px;
font-family: 'Roboto', sans-serif, 'Lato';
height: 40px;
line-height: 40px;
background-color: #00a2dc;
color: #FFF;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
border: none;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
}

.button.button-rounded {
border-radius: 3px;
}

.button.button-reveal {
padding: 0 28px;
overflow: hidden;
}

.button.button-large {
padding: 0 26px;
font-size: 16px;
height: 46px;
line-height: 46px;
}

.button-teal {
background-color: #00a2dc;
}
<div class="panel-heading">
<h2 class="panel-title">Access This Service</h2>
</div>

<div class="panel-body">
<ol class="leftmargin-sm nobottommargin">
<li>test <a href="http://google.com">test</a></li>
<li>test.</li>
<li>test. </li>
<li>test.</li>
</ol>
<a href="http://google.com" class="button button-rounded button-reveal button-large button-teal"><i class="fa fa-forward" aria-hidden="true"></i><span>Go there now!</span></a><br> Note: test <a href="http://google.com">google.com</a>.
</div>

最佳答案

我认为主要问题是您为 left 设置了转换和 right属性,但您不会在悬停时更改这些属性。

下面,我为 all 设置了转换在 <i> 上元素。悬停后,我从 width:0; 变为至 width:1em;margin-right:1em;

有关更多引用,请参阅 Using CSS Transitions .

.button-reveal i {
display: inline-block;
width: 0;
height: 1em;
overflow: hidden;
transition: all 0.3s ease;
}

.button.button-reveal:hover i {
width: 1em;
margin-right: 1em;
}

.button {
display: inline-block;
white-space: nowrap;
margin: 5px;
padding: 0 22px;
font-size: 14px;
font-family: 'Roboto', sans-serif, 'Lato';
height: 40px;
line-height: 40px;
background-color: #00a2dc;
color: #FFF;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
text-decoration: none;
}

.button.button-rounded {
border-radius: 3px;
}

.button.button-reveal {
padding: 0 28px;
overflow: hidden;
}

.button.button-large {
padding: 0 26px;
font-size: 16px;
height: 46px;
line-height: 46px;
}

.button-teal {
background-color: #00a2dc;
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<a href="http://google.com" class="button button-rounded button-reveal button-large button-teal"><i class="fa fa-forward" aria-hidden="true">&#xbb;</i><span>Go there now!</span></a>


编辑

在这个例子中,我为图标的 left 设置了动画。属性(property)使其进入视野和margin将其向右移动。

.button-reveal i {
position: absolute;
width: 2em;
height: 100%;
line-height: 45px;
background-color: rgba(0, 0, 0, .2);
text-align: center;
left: -100%;
transition: left 0.25s ease;
}
.button-reveal:hover i {
left: 0;
}

.button-reveal span {
display: inline-block;
margin: 0 2em;
transition: margin 0.35s ease;
}
.button-reveal:hover span {
margin: 0 1em 0 3em;
}

.button {
position: relative;
display: inline-block;
white-space: nowrap;
margin: 5px;
font-size: 14px;
font-family: 'Roboto', sans-serif, 'Lato';
height: 40px;
line-height: 40px;
background-color: #00a2dc;
color: #FFF;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
text-decoration: none;
}

.button.button-rounded {
border-radius: 3px;
}
.button.button-large {
font-size: 16px;
height: 46px;
line-height: 46px;
}
.button-teal {
background-color: #00a2dc;
}
.button-reveal {
overflow: hidden;
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<a href="http://google.com" class="button button-rounded button-reveal button-large button-teal"><i class="fa fa-forward" aria-hidden="true"></i><span>Go there now!</span></a>

关于html - 在我的按钮中添加 CSS 过渡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46248159/

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