【问题标题】:css hover animate doasn't work in icomooncss 悬停动画在 icomoon 中不起作用
【发布时间】:2020-06-04 07:42:08
【问题描述】:

我有带有 css3 悬停动画的菜单(toTopFromBottom)。现在我需要将 fontawesome 图标更改为 icomoon 图标并添加此效果:

HTML:

<div id="top-bar" class="top-bar">
  <div class="container">
    <div class="col-md-12">
      <div class="row">
        <div class="social-icons social-icons-colored-hover">
          <ul>
            <li class="social-facebook"><a href="#"><i class="icon-mug"></i></a></li>
            <li class="social-twitter"><a href="#"><i class="icon-rocket"></i></a></li>
            <li class="social-google"><a href="#"><i class="icon-paint-format"></i></a></li>
            <li class="social-vimeo"><a href="#"><i class="icon-pencil"></i></a></li>
          </ul>
        </div>    
      </div>
    </div>
  </div>
</div>

CSS:

#top-bar .social-icons {
  float: right;
  height: 100%;
  overflow: hidden;
}
#top-bar .social-icons li,
#top-bar .social-icons li a {
  float: left;
  list-style: outside none none;
}
#top-bar .social-icons li a {
  border-radius: 0px;
  border-right: 1px solid rgba(180, 180, 180, 0.2);
  font-size: 15px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  width: 35px;
  overflow: hidden;
  margin: 0;
}
#top-bar .social-icons li:first-child a {
  border-left: 1px solid rgba(180, 180, 180, 0.2);
}
.social-icons ul {
  padding: 0;
}
.text-center.social-icons ul {
  display: inline-block;
}
.social-icons li {
  float: left;
  list-style: none;
}
.social-icons li a {
  float: left;
  height: 32px;
  width: 32px;
  line-height: 32px;
  font-size: 16px;
  text-align: center;
  margin: 0 8px 8px 0;
  border-radius: 4px;
  border: 0;
  background: transparent;
  color: #565b73;
  overflow: hidden;
}
/*Colored*/

.social-icons.social-icons-colored a,
.social-icons.social-icons-colored-hover a:hover {
  color: #fff;
  border: 0;
}
.social-icons.social-icons-colored .social-facebook a,
.social-icons.social-icons-colored-hover .social-facebook a:hover {
  background-color: #5d82d1;
}
.social-icons.social-icons-colored .social-twitter a,
.social-icons.social-icons-colored-hover .social-twitter a:hover {
  background-color: #40bff5;
}
.social-icons.social-icons-colored .social-vimeo a,
.social-icons.social-icons-colored-hover .social-vimeo a:hover {
  background-color: #35c6ea;
}
.social-icons.social-icons-colored .social-google a,
.social-icons.social-icons-colored-hover .social-google a:hover {
  background-color: #eb5e4c;
}
/* Border */

.social-icons.social-icons-border li a {
  border: 1px solid #eee;
  background: transparent;
  color: #333;
}
.social-icons:not(.social-icons-colored):not(.social-icons-colored-hover)
  li
  a:hover {
  background-color: #eee;
}
.social-icons li:hover i {
  -webkit-animation: toTopFromBottom 0.3s forwards;
  -moz-animation: toTopFromBottom 0.3s forwards;
  animation: toTopFromBottom 0.3s forwards;
}
@-webkit-keyframes toTopFromBottom {
  49% {
    -webkit-transform: translateY(-100%);
  }
  50% {
    opacity: 0;
    -webkit-transform: translateY(100%);
  }
  51% {
    opacity: 1;
  }
}
@-moz-keyframes toTopFromBottom {
  49% {
    -moz-transform: translateY(-100%);
  }
  50% {
    opacity: 0;
    -moz-transform: translateY(100%);
  }
  51% {
    opacity: 1;
  }
}
@keyframes toTopFromBottom {
  49% {
    transform: translateY(-100%);
  }
  50% {
    opacity: 0;
    transform: translateY(100%);
  }
  51% {
    opacity: 1;
  }
}

但实际上 css 效果不适用于 icomoon。

Demo With icomoon HERE(not work)

Demo With fontawesome HERE(work true)

【问题讨论】:

    标签: html css bootstrap-4 css-transitions


    【解决方案1】:

    试试display: inline-block

    [class^="icon-"],
    [class*=" icon-"] {
      display: inline-block
      font-family: "icomoon";
      speak: none;
      font-style: normal;
      font-weight: normal;
      font-variant: normal;
      text-transform: none;
      line-height: 1;
    
      /* Better Font Rendering =========== */
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
    }
    

    Working demo

    【讨论】:

      【解决方案2】:

      您需要将display:inline-block; 添加到[class^="icon-"],[class*=" icon-"] 选择器

      在这里工作演示:https://jsfiddle.net/hb874txq/

      【讨论】:

        猜你喜欢
        • 2021-12-21
        • 2019-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-21
        • 2014-09-07
        相关资源
        最近更新 更多