【问题标题】:Little CSS animation on hover悬停时的小 CSS 动画
【发布时间】:2015-11-03 00:11:14
【问题描述】:

试图创造这样的东西。

我不能使用letter-spacing. 我创建了这段代码,但它不能很好地工作。

http://jsfiddle.net/pyqq8wfe/

.refreshed_logo {
  font-family: ProximaNovaBold;
  font-size: 50px;
  text-decoration: none;
  color: #000000;
}
.logo_wrapper {
  color: inherit;
  text-decoration: none;
  width: 250px;
  position: absolute;
}
.refreshed_logo:after {
  content: 'digital';
  width: 20px;
  height: 20px;
  text-align: center;
  position: absolute;
  font-size: 20px;
  background-color: red;
  border-radius: 18px;
  color: white;
  margin-left: 4px;
  margin-top: 3px;
  text-indent: 8px;
  font-weight: normal;
  line-height: 1;
  transition-property: width, height;
  transition-duration: 0.2s, 0.2s;
  transition-delay: 0s, 0.2s;
  -o-transition-property: width, height;
  -o-transition-duration: 0.2s, 0.2s;
  -o-transition-delay: 0s, 0.2s;
  -moz-transition-property: width, height;
  -moz-transition-duration: 0.2s, 0.2s;
  -moz-transition-delay: 0s, 0.2s;
  -webkit-transition-property: width, height;
  -webkit-transition-duration: 0.2s, 0.2s;
  -webkit-transition-delay: 0s, 0.2s;
}
.refreshed_logo:hover:after {
  width: 71px;
  -webkit-transition: width 0.5s;
  transition: width 0.5s;
  text-indent: 2px;
}
.logo_wrapper:hover {
  text-decoration: none;
}
<a href="/" class="logo_wrapper">
  <span class="refreshed_logo">
               Granat
            </span>
</a>

有什么想法吗?

【问题讨论】:

  • This 是我能想到的最好的。它在未悬停状态下手动在“d”和“i”之间引入一个空格,该空格在悬停时被删除。

标签: html css css-transitions


【解决方案1】:

由于您不能使用letter-spacing 或拆分单词,以下是使用border-right 的方法,它与overflow: hidden 设置一起隐藏“d”之后的所有字符。悬停时它们会显示出来,从而产生效果。

.refreshed_logo {
  font-family: ProximaNovaBold;
  font-size: 50px;
  text-decoration: none;
  color: #000000;
}
.logo_wrapper {
  color: inherit;
  text-decoration: none;
  width: 250px;
  position: absolute;
}
.refreshed_logo:after {
  content: 'digital';
  width: 20px;
  height: 20px;
  /*text-align: center; not required */
  position: absolute;
  font-size: 20px;
  background-color: red;
  border-radius: 18px;
  color: white;
  /* following properties were added */
  padding-left: 5px;
  box-sizing: border-box;
  border-right: 5px solid red;
  overflow: hidden;
  /* end of addition */
  font-weight: normal;
  line-height: 1;
  transition-property: width, height;
  transition-duration: 0.2s, 0.2s;
  transition-delay: 0s, 0.2s;
}
.refreshed_logo:hover:after {
  width: 65px;
  transition: width 0.5s;
}
.logo_wrapper:hover {
  text-decoration: none;
}
<a href="/" class="logo_wrapper">
  <span class="refreshed_logo">
               Granat
            </span>
</a>

【讨论】:

    【解决方案2】:

    我已经尝试了相同的结果,但可能会更好:

    最后编辑:为了隐藏其他字母,我使用了相同的背景颜色,并且只更改了第一个字母的颜色。

    CSS:

    .titre{
        font-size:20pt;
    }
    
    .sstitre{
        font-size:10pt;
        font-weight:bold;
        color:red;
        background-color:red;
        border-radius:10px;
        padding-left:4px;
        padding-right:2px;
        width:10px;
        position: absolute;
        overflow:hidden;
        transition:width 0.5s;
    }
    
    .sstitre::first-letter{
        color:white;
    }
    
    .titre:hover .sstitre{
     width:40px;   
    color:white;
    }
    

    HTML

    <span class="titre">Granat<span class="sstitre">digital</span></span>
    

    JSFidle

    【讨论】:

    • 虽然这样肯定更好,但他确实说他不能使用letter-spacing
    • 我已经提到我不能使用字母间距。
    • 已编辑!!没有字母间距和整个单词。
    猜你喜欢
    • 2014-11-02
    • 2021-01-02
    • 2012-02-09
    • 2021-04-02
    • 2014-03-22
    • 2015-04-02
    • 2019-07-23
    相关资源
    最近更新 更多