width: 280px; height: 50px; position: absolute; bottom: 60px; left: 8px; border: none;
时间: 2024-05-18 18:16:05 浏览: 20
这段代码是用来设置一个绝对定位的元素的位置和样式。具体解释如下:
- `width: 280px;` 设置元素的宽度为 280 像素。
- `height: 50px;` 设置元素的高度为 50 像素。
- `position: absolute;` 将元素的定位方式设置为绝对定位,这意味着元素的位置将相对于其最近的已定位祖先元素进行定位。如果没有已定位的祖先元素,则相对于文档进行定位。
- `bottom: 60px;` 设置元素的底部与其包含块(已定位的祖先元素或文档本身)底部的距离为 60 像素。
- `left: 8px;` 设置元素的左侧与其包含块的左侧的距离为 8 像素。
- `border: none;` 设置元素的边框样式为无边框。
相关问题
写一个HTML+JS+CSS的登录页面和一个主页 要求:登录页面包含账号密码验证,重置 验证成功跳转到主页,主页内容为一段歌词
很好,我可以为您提供这样的代码范例,但需要说明的是,这仅仅是一个大体的框架,需要您自己根据实际需求进行修改和完善。
首先,让我们来看一下 HTML 代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Login Page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="login-box">
<h2>Login Here</h2>
<form>
<div class="user-box">
<input type="text" name="username" required="">
<label>Username</label>
</div>
<div class="user-box">
<input type="password" name="password" required="">
<label>Password</label>
</div>
<input type="submit" name="" value="Submit">
<input type="reset" value="Reset">
</form>
</div>
<script src="script.js"></script>
</body>
</html>
```
在这段代码中,我们使用了一个 DIV 标签作为登录框的容器,包含了一个 H2 标签作为标题和一个 FORM 标签作为表单。表单中包含了两个 INPUT 标签,分别用于输入用户名和密码,还包含了两个按钮:Submit 和 Reset。
接下来,让我们来看一下 CSS 代码:
```css
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: sans-serif;
background: #3498db;
}
.login-box {
width: 280px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #fff;
}
.login-box h2 {
margin: 0 0 20px;
padding: 0;
text-align: center;
font-size: 22px;
}
.login-box form {
width: 100%;
position: relative;
}
.login-box form input {
width: 100%;
margin-bottom: 20px;
}
.login-box form input[type="text"],
.login-box form input[type="password"] {
border: none;
border-bottom: 1px solid #fff;
background: transparent;
outline: none;
height: 40px;
color: #fff;
font-size: 16px;
}
.login-box form input[type="submit"],
.login-box form input[type="reset"] {
border: none;
outline: none;
height: 40px;
background: #fb2525;
color: #fff;
font-size: 18px;
border-radius: 20px;
}
.login-box form input[type="submit"]:hover {
cursor: pointer;
background: #ffc107;
color: #000;
}
.login-box form input[type="reset"]:hover {
cursor: pointer;
background: #ffc107;
color: #000;
}
.login-box .user-box {
position: relative;
}
.login-box .user-box 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 .user-box label {
position: absolute;
top: 0;
left: 0;
padding: 10px 0;
font-size: 16px;
color: #fff;
pointer-events: none;
transition: 0.5s;
}
.login-box .user-box input:focus ~ label,
.login-box .user-box input:valid ~ label {
top: -20px;
left: 0;
color: #ffc107;
font-size: 12px;
}
```
在这段代码中,我们主要对登录框的样式进行了设置,包括了背景颜色、字体、输入框样式、按钮样式等等。
最后,让我们来看一下 JS 代码:
```javascript
const form = document.querySelector('form');
const username = document.querySelector('input[name="username"]');
const password = document.querySelector('input[name="password"]');
form.addEventListener('submit', (event) => {
event.preventDefault();
if (username.value === 'admin' && password.value === 'admin') {
window.location.href = 'index.html';
} else {
alert('Invalid username or password!');
}
});
form.addEventListener('reset', (event) => {
event.preventDefault();
username.value = '';
password.value = '';
});
```
在这段代码中,我们首先通过 SELECTOR 获取了表单、用户名和密码的 INPUT 元素,然后通过 EVENTLISTENER 监听表单的提交和重置事件。当表单提交时,我们首先使用 PREVENTDEFAULT 阻止默认行为,然后判断用户名和密码是否正确,如果正确则跳转到主页,否则弹出提示框。当表单重置时,我们同样使用 PREVENTDEFAULT 阻止默认行为,然后将用户名和密码的值都设置为空。
最后,让我们来看一下主页的 HTML 代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Home Page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="home-box">
<h2>Lyrics</h2>
<p>I see trees of green, red roses too</p>
<p>I see them bloom for me and you</p>
<p>And I think to myself what a wonderful world</p>
</div>
</body>
</html>
```
在这段代码中,我们使用了一个 DIV 标签作为主页的容器,包含了一个 H2 标签作为标题和三个 P 标签作为歌词的内容。
最后,让我们再来看一下 CSS 代码:
```css
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: sans-serif;
background: #3498db;
}
.home-box {
width: 280px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #fff;
text-align: center;
}
.home-box h2 {
margin: 0 0 20px;
padding: 0;
font-size: 22px;
}
.home-box p {
margin: 20px 0;
padding: 0;
font-size: 16px;
line-height: 1.5;
}
```
在这段代码中,我们主要对主页的样式进行了设置,包括了背景颜色、字体、文本居中等等。
完整的代码可以在下面的链接中找到:
https://github.com/ChitChatAI/Login-Page-and-Home-Page
建立一个用户登录页面的代码
好的,以下是一个用户登录页面的HTML和CSS代码示例:
HTML代码:<br>
```html
<!DOCTYPE html>
<html>
<head>
<title>用户登录</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="login-box">
<h1>登录</h1>
<form>
<label for="username">用户名</label>
<input type="text" id="username" placeholder="请输入用户名">
<label for="password">密码</label>
<input type="password" id="password" placeholder="请输入密码">
<input type="submit" value="登录">
</form>
</div>
</body>
</html>
```
CSS代码:<br>
```css
body {
margin: 0;
padding: 0;
background: #d3d3d3;
}
.login-box {
width: 280px;
height: 350px;
background: #fff;
color: #222;
top: 50%;
left: 50%;
position: absolute;
transform: translate(-50%,-50%);
box-sizing: border-box;
padding: 70px 30px;
box-shadow: 0 15px 25px rgba(0,0,0,.5);
border-radius: 10px;
}
h1 {
margin: 0;
padding: 0 0 20px;
text-align: center;
font-size: 22px;
}
label {
margin: 0;
padding: 0;
font-weight: bold;
display: block;
}
input[type="text"], input[type="password"] {
width: 100%;
margin-bottom: 20px;
padding: 8px 12px;
border: none;
border-bottom: 1px solid #222;
outline: none;
}
input[type="submit"] {
background: #222;
color: #fff;
border: none;
padding: 8px 12px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin-bottom: 20px;
}
```
希望这个示例可以帮助你建立一个用户登录页面。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.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)