【问题标题】:translate element inside link on hover悬停时翻译链接内的元素
【发布时间】:2013-11-10 19:04:24
【问题描述】:

我正在尝试使用 CSS3 转换将对象水平向右平移。这似乎很简单,但也许我错过了什么......

这就是我所拥有的:

<h1>
    <a href="#" class="qa">Check Q&amp;A<i class="icon-right-open-gal"></i></a>
</h1>

i 是一个放置有精灵的图像。一旦链接悬停,我希望这个元素水平向右移动。

.qa{

  &:link,&:visited{
    padding: 10px;
    text-decoration: none;
    color: #f2f2f2;
    font-size: 18px;
    // @include background-image(linear-gradient(bottom, #42BA70, #49CB7A));
    background-color: #E3560D;
    @include box-shadow(inset 1px 1px rgba(255,199,170,0.5));
    @include box-sizing(border-box);
    text-transform: uppercase;
    @include transition-property(all);
    @include transition-duration(0.2s);
    @include transition-timing-function(ease-in-out);

    i{
    font-size: 13px;
    }

    span{
      font-family: helvetica-neue, helvetica, serif;
      font-size: 15px;
    }
  }


  &:hover, &:active{
    background-color: #F77902;
    @include box-shadow(inset 1px 1px rgba(248,255,170,0.5));

      i{
      -webkit-transform: translateX(40px);
      -moz-transform: translateX(40px);
      -o-transform: translateX(40px);
      transform: translateX(40px);
      }
  } 

我尝试了几个选项,但没有一个有效。有人可以如何正确使用它。我在这个项目中使用 SASS。我在没有罗盘混合的情况下离开了 translate 属性,以使其更清晰。

【问题讨论】:

    标签: css sass transform css-transitions translate-animation


    【解决方案1】:

    问题在于&lt;i&gt; 标记是内联的。它需要一个布局才能被翻译。为此,只需给它一个display: inline-block 属性,一切都很好。看这个简单的小提琴http://jsfiddle.net/WxqCw/

    【讨论】:

    • 谢谢!有效。我已经不止一次在这个问题上找到自己了,现在知道什么是内联的。您是否知道任何有助于了解什么是内联元素以及哪些元素是内联的文档? PD它对我有用,但小提琴现在不起作用......
    • 对小提琴感到抱歉。关于学习哪些是内联/块元素,我建议查看 mdn:https://developer.mozilla.org/en-US/docs/Web/HTML/Element
    • 这里有相关链接:inline elementsblock elements
    猜你喜欢
    • 2021-08-22
    • 2011-07-31
    • 2016-07-18
    • 1970-01-01
    • 2017-01-23
    • 2011-02-15
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    相关资源
    最近更新 更多