HTML+CSS 实现一个简单的登录页面 (背景图片完全适应 不失帧)

4 篇文章 0 订阅
3 篇文章 1 订阅

 

 

 

 

HTML:

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		 <link rel="stylesheet" type="text/css" href="css/tx1.css" />
		
	</head>
	<body>

			<div class="login-box">
			<h2>Login</h2>
			<form>
				<div class="login-field">
					<input type="text" name="" required="" />
					<label>Username</label>
				</div>
				<div class="login-field">
					<input type="password" name="" required="" />
					<label >Password</label>
				</div>
				<button type="submit">Submit</button>
			</form>
		</div>

		
		 
	</body>
</html>

css:

body{
	margin: 0;
	padding: 0;
	font-family: sans-serif;
	background: url(../img/bg.jpg)  no-repeat center 0px;
	background-size: cover;

	

     background-position: center 0; 
     background-repeat: no-repeat;  
     background-attachment: fixed; 
      -webkit-background-size: cover;  
      -o-background-size: cover;  
      -moz-background-size: cover;  
      -ms-background-size: cover;
	
}
.login-box{
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%,-50%);
	width: 400px;
	padding:40px;
	background: rgba(0,0,0,.8);
	box-sizing: border-box;
	box-shadow: 0 15px  25px rgba(0,0,0,.5);
	border-radius: 10px;
}
.login-box h2{
	margin: 0 0 30px;
	padding: 0;
	text-align: center;
	color: #fff;
}
.login-box .login-field{
	position: relative;
}
.login-box .login-field  input{
	width: 100%;
	padding: 10px 0;
	font-size: 16px;
	color: #fff;
	margin-bottom: 30px;
	border: none;
	border-bottom: 1px solid #fff;
	outline: none;
	background: transparent;
}
.login-box .login-field  label{
	position: absolute;
	top: 0;
	left: 0;
	letter-spacing: 1px;
	padding: 10px 0;
	font-size: 16px;
	color: #fff;
	pointer-events: none;
	transition: .5s;
}
.login-box .login-field input:focus ~ label,
.login-box .login-field input:valid ~ label{
	top: -23px;
	left: 0;
	color: aqua;
	font-size: 12px;
}
.login-box button{
	background: transparent;
	border: none;
	outline: none;
	color: #fff;
	background: #03a9f4;
	padding: 10px 20px;
	cursor: pointer;
	border-radius: 5px;
}

 

 

 

  • 45
    点赞
  • 160
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
好的,为了实现火影忍者的背景切换登录页面,我们需要用到HTMLCSS和JS。首先,我们需要准备好背景图片,这里我选择了几张火影忍者的图片。 接下来,我们可以开始编写代码了。 HTML代码: ```html <!DOCTYPE html> <html> <head> <title>火影忍者登录页面</title> <link rel="stylesheet" type="text/css" href="style.css"> <script type="text/javascript" src="script.js"></script> </head> <body> <div id="bg-img"></div> <div class="container"> <form> <h1>火影忍者登录</h1> <input type="text" placeholder="用户名"> <input type="password" placeholder="密码"> <button type="submit">登录</button> </form> </div> </body> </html> ``` 我们在页面中添加了一个id为“bg-img”的div,用来显示背景图片。我们还添加了一个class为“container”的div,用来包含登录表单。 CSS代码: ```css body { margin: 0; padding: 0; background-color: #000; } #bg-img { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; background-size: cover; background-position: center; animation: bg-slide 20s infinite; } @keyframes bg-slide { 0% { background-image: url("bg1.jpg"); } 25% { background-image: url("bg2.jpg"); } 50% { background-image: url("bg3.jpg"); } 75% { background-image: url("bg4.jpg"); } 100% { background-image: url("bg5.jpg"); } } .container { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: rgba(255, 255, 255, 0.8); padding: 30px; border-radius: 5px; box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.3); } h1 { text-align: center; font-size: 32px; margin-bottom: 20px; } input { display: block; width: 100%; padding: 10px; margin-bottom: 20px; font-size: 16px; border: none; border-radius: 5px; box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.3); } button { display: block; width: 100%; padding: 10px; background-color: #c9302c; color: #fff; font-size: 16px; border: none; border-radius: 5px; cursor: pointer; } button:hover { background-color: #a52725; } ``` 在CSS中,我们设置背景图片的位置、大小和动画。我们使用了@keyframes来实现背景图片的切换,每25%的时间显示一张不同的图片。我们还设置了登录表单的样式,包括位置、颜色、边框和阴影等。 JS代码: ```javascript window.onload = function() { var bgImg = document.getElementById("bg-img"); var bgImgs = ["bg1.jpg", "bg2.jpg", "bg3.jpg", "bg4.jpg", "bg5.jpg"]; var index = 0; setInterval(function() { index++; if (index == bgImgs.length) { index = 0; } bgImg.style.backgroundImage = "url(" + bgImgs[index] + ")"; }, 20000); } ``` 在JS中,我们使用了一个定时器来实现背景图片的切换。我们设置一个数组来存储背景图片的路径,然后每隔20秒就切换一次背景图片。 最后,我们将HTMLCSS和JS保存到同一个文件夹中,然后我们就可以在浏览器中打开这个文件来查看火影忍者的背景切换登录页面了。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值