Html 使用 CSS 从右向左滑动边框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31180810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:43:49  来源:igfitidea点击:

Sliding border from right to left using CSS

htmlcsssliding

提问by MasterDex

I have a header that I want to have a border on that slides from right to left on hover, using pure CSS if that's possible.

我有一个标题,我想在悬停时从右向左滑动的边框上有一个边框,如果可能的话,使用纯 CSS。

At the moment, I can get a border that slides from left to right using the following CSS:

目前,我可以使用以下 CSS 获得一个从左向右滑动的边框:

#header a:after {
content: '';
display: block;
border-bottom: 3px solid $(header.hover.color);
width: 0;
-webkit-transition: 1s ease;
        transition: 1s ease;
}

#header a:hover:after { width: 100%; }

Has anyone a good solution for accomplishing this task?

有没有人有一个很好的解决方案来完成这项任务?

回答by Bogdan Ku?tan

You can position your :afterelement to the right

您可以将:after元素放在右侧

#header {
  position: relative;
}
#header a:after {
  content: '';
  display: block;
  border-bottom: 3px solid red;
  width: 0;
  position: absolute;
  right: 0;
  -webkit-transition: 1s ease;
  transition: 1s ease;
}

#header a:hover:after { 
  width: 100%; 
}

回答by Praveen Kumar Purushothaman

Give all:

所有都给:

-webkit-transition: 1s all ease;
        transition: 1s all ease;