css - 过渡不适用于文本

标签 css css-transitions

<分区>

我添加了代码以在将鼠标悬停在文本上时放大文本,但它不起作用。任何人都可以看到原因吗?这是我的 jsfiddle.我认为这不重要,但实际代码中使用的字体是通过 font-face 加载的,但我想我应该提一下。

    <style>
    .headerText {transition: all .2s ease-in-out;}
    .headerText:hover {transform: scale(2.1);}
    a.headerText {
       font-family: arial;
       font-weight:bold;
       font-style:none;
       font-size:28px; 
       text-decoration:none;
       text-align:center;  
       color:purple;
       white-space:nowrap;  
       margin-left:20px;
       line-height:1.6;   
    }
    a.headerText:hover {color:green;}
    </style>

    <span class="headerText"><a class="headerText" href="http://example.com">my link</a></span> 

最佳答案

Transform 属性不适用于内联元素,并且 <span>就是其中之一。

Here您可以看到可以转换的元素列表。

A transformable element is an element in one of these categories:

  • an element whose layout is governed by the CSS box model which is either a block-level or atomic inline-level element, or whose display property computes to table-row, table-row-group, table-header-group, table-footer-group, table-cell, or table-caption [CSS2]

  • an element in the SVG namespace and not governed by the CSS box model which has the attributes transform, patternTransform or gradientTransform [SVG11].

解决方案

设置display跨度的属性 inline-blockblock .

.headerText {
  display: inline-block;
  transition: all .2s ease-in-out;
}

.headerText:hover {
  transform: scale(2.1);
}

a.headerText {
  font-family: arial;
  font-weight: bold;
  font-style: none;
  font-size: 28px;
  text-decoration: none;
  text-align: center;
  color: purple;
  white-space: nowrap;
  margin-left: 20px;
  line-height: 1.6;
}

a.headerText:hover {
  color: green;
}
<span class="headerText">
  <a class="headerText" href="http://example.com">
    my link
  </a>
</span>

关于css - 过渡不适用于文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51123801/

上一篇:javascript - 如何检查一个类是否有值并在之后切换一个类

下一篇:Javascript .click() 回调函数显然没有在 Bootstrap Accordion 中调用?

相关文章:

css - CSS显示属性上的过渡

CSS 卡片翻转动画在 Safari/Firefox 中落后于另一张卡片

html - 行内网格元素的垂直对齐

javascript - 防止选择 rt 标签(furigana)中的文本

css - 有没有办法调整高度以匹配另一幅图像的中点?

html - 如何无限连续自动滚动充满图像的div元素?

css - 了解 CSS 中的 cubic-bezier 过渡属性

css 过渡持续时间不适用于矢量效果 : non-scaling-stroke

css - 使用 CSS 在鼠标悬停时显示子类

html - 截断的文本在 Mozilla 中表现不同