响应式登录页左右布局,左侧登录插图示例
时间: 2023-07-28 16:27:52 浏览: 49
你可以尝试使用Bootstrap等前端框架来实现响应式登录页左右布局,其中左侧登录插图可以使用一张图片或者一个动态的GIF图来装饰。以下是一个简单的HTML和CSS示例代码:
```
<!DOCTYPE html>
<html>
<head>
<title>响应式登录页</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<style>
.login-img {
background-image: url('login-image.jpg');
background-size: cover;
height: 100vh;
min-height: 500px;
background-position: center;
position: relative;
}
.login-form {
background-color: #f1f1f1;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 0px 10px 2px #ccc;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-width: 500px;
width: 90%;
}
@media screen and (min-width: 768px) {
.login-img {
width: 50%;
display: inline-block;
height: auto;
position: relative;
}
.login-form {
display: inline-block;
margin-left: 50px;
vertical-align: middle;
position: static;
transform: none;
max-width: 400px;
}
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-12 col-md-6 login-img"></div>
<div class="col-12 col-md-6">
<form class="login-form">
<h2>登录</h2>
<div class="form-group">
<label for="username">用户名:</label>
<input type="text" class="form-control" id="username" placeholder="请输入用户名">
</div>
<div class="form-group">
<label for="password">密码:</label>
<input type="password" class="form-control" id="password" placeholder="请输入密码">
</div>
<button type="submit" class="btn btn-primary">登录</button>
</form>
</div>
</div>
</div>
</body>
</html>
```
在上面的代码中,我们使用了Bootstrap的网格系统来实现响应式布局。在小屏幕设备上,图片和表单都是垂直排列的,而在大屏幕设备上,图片和表单是水平排列的。图片的样式使用了CSS的background-image属性来设置,而表单的样式使用了Bootstrap的类来设置。你可以将login-image.jpg替换为你自己的图片。