写一个登录页面,样式大方,能兼容pc端和移动端
时间: 2024-03-11 07:50:56 浏览: 41
好的,我可以给您提供一个简单的登录页面的 HTML 和 CSS 代码,并且可以适配不同的屏幕大小。以下是代码示例:
HTML代码:
```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录页面</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>欢迎登录</h1>
<form>
<label for="username"><b>用户名</b></label>
<input type="text" placeholder="请输入用户名" name="username" required>
<label for="password"><b>密码</b></label>
<input type="password" placeholder="请输入密码" name="password" required>
<button type="submit">登录</button>
<label>
<input type="checkbox" checked="checked" name="remember">记住我
</label>
</form>
</div>
</body>
</html>
```
CSS代码:
```
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
background-color: #f1f1f1;
}
.container {
padding: 16px;
background-color: #fff;
}
h1 {
text-align: center;
color: #333;
}
input[type=text], input[type=password] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
button[type=submit] {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
width: 100%;
}
button[type=submit]:hover {
background-color: #45a049;
}
label {
display: block;
color: #666;
}
input[type=checkbox] {
margin-top: 16px;
}
@media screen and (min-width: 768px) {
/* PC端样式 */
.container {
width: 50%;
margin: 50px auto;
}
}
@media screen and (max-width: 767px) {
/* 移动端样式 */
.container {
width: 90%;
margin: 50px auto;
}
}
```
该页面使用了一个容器来包含登录表单,使用了一些常见的样式来美化表单元素。在 CSS 代码中,我们使用了媒体查询来适配不同大小的屏幕。在屏幕宽度大于等于 768px 时,应用 PC 端样式;在屏幕宽度小于 768px 时,应用移动端样式。
希望这个登录页面的示例能够帮助到您!
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)