从下到上的动画边框颜色变化?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从下到上的动画边框颜色变化?相关的知识,希望对你有一定的参考价值。

因此,我一直在寻找一种方法来更改导航栏链接底部边框的颜色,并使用从底部向上开始的线性动画。我能够找到一个带有一些我半明白的代码的线程,只有几行CSS行向正确的方向发送了我,但是颜色的变化是自上而下的,而我希望相反。

我正在使用Bootstrap,如果有什么不同,我有什么办法可以做相反的事情,并使过渡过程从底部开始并向上?我的代码发布在下面...

* {
	box-sizing: border-box;
}

body {}

#header-nav {
	background-color: #262626;
	font-family: 'Kanit', sans-serif;
	font-size: 1.1em;
	text-transform: uppercase;
	border-bottom: #212121 thick solid;
}

#header-nav .container {
	padding-top: 10px;
	padding-bottom: 10px;
/*	border-bottom: purple thick solid;*/
	margin: 0px;
}
/*212121*/
#header-nav a {
	color: #FFF;
	margin-right: 2rem;
	padding: 10px;
/*	border-bottom: purple thick solid; */
	transition-property: all;
	transition-duration: 0.5s;
	transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
}

#header-nav a:hover {
	text-decoration: none;
/*	background-color: purple;*/
	border-bottom: white thick solid;
}
<!DOCTYPE html>
<html>

	<head>

		<!-- Meta & Other -->
		<title>Infamous | Home</title>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="description" content="Infamous official website">
		<meta name="keywords" content ="Infamous, Minecraft, Server, Game, Gaming">
		<meta name="author" content="MrWardy">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		
		<!-- CSS -->
		<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
		<link rel="stylesheet" href="./Stylesheets/default.css">
		
		<!-- Fonts -->
		<script src="https://kit.fontawesome.com/35fad75205.js" crossorigin="anonymous"></script>
		<link href="https://fonts.googleapis.com/css2?family=Kanit&display=swap" rel="stylesheet">
	
	

	</head>



	<body>

		<header>
			<nav id="header-nav" class="navbar-nav ml-auto">
				<div class="container">
					<a class="active" href="#"><i class="fas fa-home"></i> Home</a>
					<a href="#about"><i class="fas fa-question"></i> About</a>
					<a href="#rules"><i class="fas fa-book"></i> Rules</a>
					<a href="#vote"><i class="fas fa-vote-yea"></i> Vote</a>
					<a href="#store"><i class="fas fa-tags"></i> Store</a>
				</div>
			</nav>
		</header>

		<!-- JavsScript -->
		<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
		<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
		<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>

	</body>

</html>
答案

为此使用渐变:

.box {
  background:#000;
  padding:10px 20px;
}

a {
  display:inline-block;
  color:#fff;
  font-size:30px;
  text-decoration:none;
  padding-bottom:10px; /* control the space for the gradient */
  background:
   linear-gradient(currentColor,currentColor) 
   bottom /* make it bottom */
   /100% 0px  /*start at heght = 0; */
   no-repeat;
  transition:0.3s all;
}
a:hover {
  background-size:100% 6px; /* make the height 6px*/
}
<div class="box">
  <a href=""> a link </a>
</div>

以上是关于从下到上的动画边框颜色变化?的主要内容,如果未能解决你的问题,请参考以下文章

从下到上堆叠 div

Swiftui 动态动画面板从下到上

在jQuery中从下到上动画div而不是从上到下[重复]

jQuery Animate 顶部(从下到上)

xcode - 从下到上的 TableView 行

Laravel 8 从下到上的路线顺序