首页 > 解决方案 > 使用 css 移动箭头动画

问题描述

当我将鼠标悬停在它所在的元素上时,我想制作一个向右移动的箭头。现在我的两个元素同时移动。(h3和span)。

箭头和文本必须在同一行。只有箭头应该移动。我只需要使用 html 和 css(没有 js 或 ajax)。

.container-fluid .blue-row {
    background-color: #03a9f4;
    width: 100%;
    margin: auto;
}

.container-fluid .blue-row h3 {
    color: white;
    font-size: 39px;
    text-align: center;
    vertical-align: center;
    padding: 40px;
    font-weight: bold;
}

.container-fluid .blue-row h3 span {
    margin-left: 5%;
    transition: 1s;
}

.container-fluid .blue-row:hover > h3 span {
    margin-left: 10%;
}
<div class="container-fluid">
    <div class="blue-row">
        <h3>Check how we can kickstart your smart projects<span>&#10230;</span></h3>
    </div>
</div>

标签: htmlcss

解决方案


使用规则transform: translateX()悬停,最好是默认。另外,span使用 rule 制作块display: inline-block

.container-fluid .blue-row {
    background-color: #03a9f4;
    width: 100%;
    margin: auto;
}

.container-fluid .blue-row h3 {
    color: white;
    font-size: 39px;
    text-align: center;
    vertical-align: center;
    padding: 40px;
    font-weight: bold;
}

.container-fluid .blue-row h3 span {
    display: inline-block;
    transform: translateX(20%);
    transition: 1s;
}

.container-fluid .blue-row:hover > h3 span {
    transform: translateX(50%);
}
<div class="container-fluid">
    <div class="blue-row">
        <h3>Check how we can kickstart your smart projects<span>&#10230;</span></h3>
    </div>
</div>


推荐阅读