亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

CSS 懸停前后背景圖像

CSS 懸停前后背景圖像

溫溫醬 2023-09-11 16:22:59
當您將鼠標懸停在圖像上時,藍色箭頭緩慢移動。當您將光標從圖像上移開時,白色箭頭會急劇返回。如何讓白色箭頭緩慢返回?@keyframes left_to_right {    from {margin-left: -15px;}    to {margin-left: 0; }}div .footer-text{    position: absolute;    top: 10%;    left: 3%;    height: 20px;    width: 85%;}div .footer-text:after{    content: '';    background: url('https://www.nsartmuseum.ru/images/test/arrow-after-3.png') no-repeat;    width: 130px;    height: 15px;    display: inline-block;    margin-left: 10px;    position: relative;}div:hover .footer-text:before{    content: '';    background: url('https://www.nsartmuseum.ru/images/test/arrow-before-3.png') no-repeat;    width: 130px;    height: 15px;    margin-right: 5px;    display: inline-block;    animation: left_to_right 0.4s ease;}div:hover .footer-text:after{    content: '';    background: none;}div .footer-text span{    position: relative;    top:-5px;    font-size: 12px;    color: #313B78;    display: inline-block;}<div><a href="" class='footer-text'>  <span>13 September</span></a></div>顯然,有很多方法可以通過 CSS 動畫來做到這一點,但我從未在開發中使用過它。
查看完整描述

3 回答

?
森欄

TA貢獻1810條經驗 獲得超5個贊

不需要animation為此使用。transition只需添加transition: width .4s ease;到:after未懸停的元素并使用width屬性就足夠了


div .footer-text{

    position: absolute;

    top: 10%;

    left: 3%;

    height: 20px;

    width: 85%;

}


div .footer-text span{

    position: relative;

    top:-5px;

    font-size: 12px;

    color: #313B78;

    display: inline-block;

}


div .footer-text:after{

    content: '';

    background: url('https://www.nsartmuseum.ru/images/test/arrow-after-3.png') no-repeat right;

    width: 130px;

    height: 15px;

    display: inline-block;

    margin-left: 10px;

    position: relative;

    transition: width .4s ease;

}


div:hover .footer-text:after{

    width: 0;

}


div .footer-text:before{

    content: '';

    background: url('https://www.nsartmuseum.ru/images/test/arrow-before-3.png') no-repeat right;

    width: 0;

    height: 15px;

    margin-right: 5px;

    display: inline-block;

    transition: width .4s ease;

}

div:hover .footer-text:before{

    width: 130px;

}

<div>

<a href="" class='footer-text'>

  <span>13 September</span>

</a>

</div>


查看完整回答
反對 回復 2023-09-11
?
MMTTMM

TA貢獻1869條經驗 獲得超4個贊

@keyframes left_to_right {

  from {

    margin-left: -15px;

  }

  to {

    margin-left: 0;

  }

}


div .footer-text {

  position: absolute;

  top: 10%;

  left: 3%;

  height: 20px;

  width: 85%;

}


div .footer-text:after {

  content: '';

  background: url('https://www.nsartmuseum.ru/images/test/arrow-after-3.png') no-repeat;

  width: 130px;

  height: 15px;

  display: inline-block;

  margin-left: 10px;

  position: relative;

  animation: left_to_right 0.4s ease;

}


div:hover .footer-text:before {

  content: '';

  background: url('https://www.nsartmuseum.ru/images/test/arrow-before-3.png') no-repeat;

  width: 130px;

  height: 15px;

  margin-right: 5px;

  display: inline-block;

  animation: left_to_right 0.4s ease;

}


div:hover .footer-text:after {

  display: none;

}


div .footer-text span {

  position: relative;

  top: -5px;

  font-size: 12px;

  color: #313B78;

  display: inline-block;

}

<div>

  <a href="" class='footer-text'>

    <span>13 September</span>

  </a>

</div>


查看完整回答
反對 回復 2023-09-11
?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

我這樣做:)


div {

  width:50%;

  position: relative;

  height: 20px;

}

div .footer-text{

    position: absolute;

    top: 0;

    left: 0;

    line-height: 20px;

    width: 100%;

    height: 100%;

    font-family: sans-serif;

    overflow: hidden;

}

div .footer-text:before {

  content: '';

  background: url('data:image/svg+xml;charset=utf-8,%3Csvg%20width%3D%228%22%20height%3D%2215%22%20viewBox%3D%220%200%208%2015%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M1%201.5l6%206-6%206%22%20stroke%3D%22%23C5C8D0%22%20stroke-width%3D%221.2%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%3C%2Fsvg%3E') no-repeat right center;

  background-size: 8px;

  width: 8px;

  height: 15px;

  position: absolute;

  right: 0;

  top: 50%;

  transform: translate(0,-7px);

  z-index: 2;

  transition: .4s ease-in-out;

}


div .footer-text span {

    position: absolute;

    top: 0;

    left: 0;

    font-size: 12px;

    color: #313B78;

    display: block;

    white-space: nowrap;

    z-index: 1;

    transition: .4s ease-in-out;

}

div .footer-text span:before {

    content: '';

    display: block;

    width: 100vw;

    height: 15px;

    position: absolute;

    top: 50%;

    right: 100%;

    margin: -7px 20px 0 0;

    background: url('data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%221110%22%20height%3D%2214%22%20viewBox%3D%220%200%201110%2014%22%3E%3Cpath%20fill%3D%22%23313B78%22%20d%3D%22M1109.424%206.076l-6-6a.599.599%200%2010-.848.848l4.975%204.976H1a.6.6%200%20100%201.2h1106.551l-4.975%204.976a.599.599%200%2010.848.848l6-6a.6.6%200%20000-.848z%22%2F%3E%3C%2Fsvg%3E') no-repeat right top;

    background-size: auto 14px;

}

div .footer-text span:after {

    content: '';

    display: block;

    width: 100vw;

    height: 1px;

    position: absolute;

    top: 50%;

    background: #C5C8D0;

    left: calc(100% + 20px);

}

div .footer-text:hover:before {

    transform: translate(20px,-7px);

}

div .footer-text:hover span {

    left: 100%;

    transform: translateX(-100%);

}

<div>

<a href="" class='footer-text'>

  <span>13 September</span>

</a>

</div>


查看完整回答
反對 回復 2023-09-11
  • 3 回答
  • 0 關注
  • 131 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號