簡單HTML+CSS+JavaScript實現簡約時尚登錄頁面詳解 動態+漸變

在這裏插入圖片描述

html代碼

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<link rel="stylesheet" href="css/style.css" />
	<script src="js/jquery-1.12.4.js"></script>
	<body>
		<form action="index.html" class="login-form">
			<h1>Login</h1>
			
			<div class="txtb">
				<input type="text" />
				<span data-placeholder="Username"></span>
			</div>
			<div class="txtb">
				<input type="password" />
				<span data-placeholder="Password"></span>
			</div>
			<input type="submit" class="logbtn" value="Login"/>
			
			<div class="bottom-text">
				Don't hava account?<a href="#">Sign up</a>
				
			</div>
		</form>
		<script type="text/javascript">
			// 當輸入框獲得焦點時給其添加focus類達到
			// 字體上移及橫線顏色波動效果
			$(".txtb input").on("focus",function(){
				$(this).addClass("focus");
				
			});
			
			// 當輸入框時區焦點時將類移除以消除效果
			$(".txtb input").on("blur",function(){
				if($(this).val()=="")
				$(this).removeClass("focus");
				
			});
		</script>
	</body>
</html>

樣式代碼


*{
	margin:0;
	padding:0;
	text-decoration: none;
	font-family: montserrat;
}
body{
	/* 設置段落的最小高度: */
	min-height: 100vh;
	/* linear-gradient:創造漸變效果 */
	background-image: linear-gradient(120deg,#3498db,#8e44ad);
}

.login-form{
	width:360px;
	background-color: #f1f1f1;
	height: 580px;
	/* padding:上內邊距和下內邊距是 80px,右內邊距和左內邊距是 40px*/
	padding: 80px 40px;
	/* border-radius:形狀處理 */
	border-radius: 10px;
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%,-50%);
}

.login-form h1{
	text-align: center;
	margin-bottom: 60px ;
}

.txtb{
	border-bottom: 2px solid #adadad;
	position:relative;
	margin: 30px 0;
}

.txtb input{
	font-size: 15px;
	color:#333;
	border: none;
	width: 100%;
	outline: none;
	background: none;
	padding: 0 5px;
	height: 40px;
	
}

/* .txtb span::before:對應span之前的元素
	在這裏表示username和password
 */
.txtb span::before{
	content: attr(data-placeholder);
	position: absolute;
	top: 50%;
	left: 5px;
	color:#ADADAD;
	transform: translateY(-50%);
	z-index: -1;
	transition: .5s;
	
}

/* .txtb span::after:對應span之之後的元素
	在這裏表示username和password下面的橫線,不是input框的橫線
 */
.txtb span::after{
	content: "";
	position: absolute;
	width: 0%;
	height: 2px;
	background:linear-gradient(120deg,#3498db,#8e44ad);
	transition: .5s;

}

/* 對span之前的元素設置focus效果
   設置字樣上移
*/
.focus + span::before{
	top: -5px;
}

/* 對span之前的元素設置focus效果
   設置橫線變色
 */
.focus + span::after{
	width:100%;
}


.logbtn{
	width: 100%;
	height: 50px;
	border: none;
	background: linear-gradient(120deg,#3498db,#8e44ad,#3498db);
	background-size: 200%;
	color: #fff;
	/* cursor:pointer:設置鼠標樣式 */
	cursor:pointer;
	transition: .5s;
}

/* 設置login按鈕背景顏色向右移動
	達到漸變效果
*/
.logbtn:hover{
	background-position:right ;
}

.bottom-text{
	margin-top:60px;
	text-align: center;
	font-size: 13px;
}

僅在學習過程中記錄所學內容,如有何處不足還請大佬們指出,歡迎同行一起交流。聯繫我微信chenhan-wu,記得備註csdn

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章