微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

css3文字下面出现下划线特效

CSS3中可以轻松实现文字下划线特效。我们可以使用text-decoration添加下划线。

  .underline {
    text-decoration: underline;
  }

css3文字下面出现下划线特效

上面的代码可以为某个元素添加下划线。如果只想为文字添加下划线,可以将元素设置为inline-block或inline,并将line-height设为0。

  .text-underline {
  display: inline-block;
  line-height: 0;
  text-decoration: underline;
  }

上述代码可以实现文字下划线特效。如果想让下划线更加有趣,我们可以添加一些动画效果

  .text-underline {
    position: relative;
    display: inline-block;
    line-height: 0;
    text-decoration: none;
    color: #333;
    transition: color 0.3s ease-in-out;
  }
  .text-underline:hover {
    color: #ff7b00;
    transition: color 0.3s ease-in-out;
  }

  .text-underline:after {
    content: '';
    position: absolute;
    left: 0;
    bottom: -2px;
    width: 100%;
    height: 2px;
    background-color: #ff7b00;
    transform: scaleX(0);
    transform-origin: right;
    transition: transform 0.3s ease-in-out;
  }

  .text-underline:hover:after {
    transform: scaleX(1);
    transform-origin: left;
  }

上述代码实现了文字悬停时下划线颜色和长度可变化的特效。我们可以根据实际需求更改颜色和动画。这些简单的技巧可以帮助我们更好地为网站添加各种各样的特效。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。