在html考试登录页面运行的好看的css背景代码,而且无引用图片
时间: 2023-12-22 08:23:47 浏览: 45
以下是一个不需要引用图片的HTML和CSS样式,可以创建一个漂亮的渐变背景效果:
HTML 代码:
```
<!DOCTYPE html>
<html>
<head>
<title>登录页面</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="background-gradient"></div>
<div class="login-box">
<h1>Login</h1>
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter your username">
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter your password">
<input type="submit" value="Login">
</form>
</div>
</body>
</html>
```
CSS 样式:
```
body {
padding: 0;
margin: 0;
background-color: #f1f1f1;
}
.background-gradient {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: linear-gradient(to bottom right, #28a745, #007bff);
z-index: -1;
}
.login-box {
width: 300px;
padding: 20px;
background-color: #fff;
margin: 100px auto;
box-shadow: 0px 0px 10px #888888;
}
.login-box h1 {
font-size: 32px;
text-align: center;
margin-bottom: 30px;
}
form label {
display: block;
margin-bottom: 10px;
}
form input[type="text"], form input[type="password"] {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border-radius: 5px;
border: none;
}
form input[type="submit"] {
background-color: #4CAF50;
color: #fff;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
}
```
在这个例子中,我们在 HTML 文件中添加了一个名为 `.background-gradient` 的 div 元素。在 CSS 样式中,我们使用 `background-image` 属性设置渐变背景,将从绿色到蓝色。我们还使用 `linear-gradient` 函数来指定渐变的方向。
注意:在实际开发中,应该根据实际需要调整渐变的颜色和方向,以创建自己的独特效果。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)
![](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)