【前端学习之HTML&CSS进阶篇】-- HTML第五篇 – 表单练习(Bilibili注册界面模仿)
本文具体内容参考了B站渡一教育的课程,原课程链接如下:
渡一教育课程
前言
html与css以及今后我们将会学到的js共同构成了前端技术中最重要的三种语言,在学习过程中,我们首先从html出发,在html的学习过程中深入了解css。
在前几节博客中我们学习到了HTML中的表单元素,并简单了解了一下美化样式,这节博客我们来以B站的注册界面为例,进行一个简单的实际练习。
代码实现
.clearfix::after{
content: "";
display: block;
clear: both;
}
body{
line-height: 1.5;
background-image: url(../bg.png);
}
.gap{
margin-top: 200px;
}
.form{
width: 980px;
margin: 1em auto;
}
.form h2{
text-align: center;
font-size: 38px;
border-bottom: 1px solid #ddd;
height: 30px;
margin-bottom: 60px;
}
.form h2 span{
background-color: #fff;
padding: 0 20px;
}
/* 统一a元素颜色 */
a{
color: #00a1d6;
}
/* 统一文本框样式 */
input[type="text"], input[type="password"]{
border: 1px solid #dcdfe6;
width: 100%;
box-sizing: border-box;
border-radius: 4px;
height: 40px;
text-indent: 1em;
font-size: 14px;
color: #606266;
font-family: PingFangSC-Medium;
}
input[type="text"]:hover, input[type="password"]:hover{
border-color: #c0c4cc;
}
input[type="text"]::placeholder, input[type="password"]::placeholder{
color: #ccc;
}
input[type="text"]:focus, input[type="password"]:focus{
border-color: #00a1d6;
}
/* 表单区域 */
.form .form-area{
width: 423px;
margin: 0 auto;
}
.form .form-area .form-item{
margin: 50px 0;
position: relative;
}
.form .form-area .form-item .error{
position: absolute;
width: 240px;
right: -250px;
color: #f45d90;
top: 10px;
font-size: 12px;
/* 默认隐藏,方便JS书写 */
display: none;
}
/* 当左边的输入有错误时,显示错误信息 */
.form .form-area .form-item.haserror .error{
display: block;
}.form .form-area .form-item.haserror input{
border-color: #f45d90;
}
.form .form-area .form-item .select .select-item{
float: left;
height: 40px;
width: 140px;
border: 1px solid #dcdfe6;
border-radius: 4px;
box-sizing: border-box;
border-right: 0;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
.form .form-area .form-item .select .select-item{
position: relative;
}
.form .form-area .form-item .select .select-item ul{
/* 默认隐藏 */
display: none;
/* 最大高度 */
max-height: 256px;
/* 溢出滚动条 */
overflow-y: scroll;
color: #606266;
background-color: #fff;
padding: 10px 0;
position: absolute;
z-index: 1;
left: 0;
top: 50px;
width: 100%;
box-sizing: border-box;
border: 1px solid #dcdfe6;
border-radius: 4px;
font-size: 14px;
}
.form .form-area .form-item .select .select-item ul li{
height: 34px;
padding: 0 20px;
cursor: pointer;
line-height: 34px;
}
.form .form-area .form-item .select .select-item ul li:first-child{
color: #00a1d6;
font-weight: bold;
}
.form .form-area .form-item .select .select-item ul li:hover{
background-color: #f5f7fa;
}
.form .form-area .form-item .select .input{
float: left;
height: 40px;
width: 283px;
}
.form .form-area .form-item .select .input input{
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}
.form .form-area .form-item .select .select-item .title{
padding: 0 20px;
height: 40px;
line-height: 40px;
color: #909399;
cursor: pointer;
}
.form .form-area .form-item button{
height: 40px;
background-color: #00a1d6;
color: #fff;
cursor: pointer;
border-radius: 4px;
font-size: 14px;
}
.form .form-area .form-item button:hover{
background-color: #33b4de;
}
.form .form-area .form-item .sncode{
width: 130px;
height: 36px;
position: absolute;
right: 2px;
top: 2px;
}
.form .form-area .readme{
margin-top: -40px 0;
font-size: 12px;
}
.form .form-area .readme .checkbox{
display: inline-block;
width: 14px;
height: 14px;
border: 1px solid #dcdfe6;
border-radius: 4px;
box-sizing: border-box;
}
.form .form-area .readme input{
display: none;
}
.form .form-area .readme input:checked+.checkbox{
border-color: #00a1d6;
}
.form .form-area .readme input:checked+.checkbox::after{
content: "";
display: block;
width: 7px;
height: 7px;
background-color: #33b4de;
border-radius: 2px;
margin-left: 2.5px;
margin-top: 2.5px;
}
.form .form-area .form-item .fill{
box-sizing: border-box;
width: 100%;
}
.form .form-area .tip{
margin-top: -40px;
font-size: 12px;
text-align: right;
}
/* 禁用状态 */
button:disabled{
background-color: #f5f5f5;
color: rgba(0, 0, 0, .25);
border: 1px solid #d9d9d9;
box-sizing: border-box;
cursor: not-allowed;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>注册页面</title>
<link rel="stylesheet" href="./css/reset.css">
<link rel="stylesheet" href="./css/routine.css">
</head>
<body>
<div class="gap"></div>
<div class="form">
<h2>
<span>注册</span>
</h2>
<div class="form-area">
<div class="form-item">
<!-- <div class="form-item haserror"> -->
<input type="text" placeholder="账号">
<div class="error">
该昵称已被他人占用
</div>
</div>
<div class="form-item">
<!-- <div class="form-item haserror"> -->
<input type="password" placeholder="密码 (6-16个字符组成,区分大小写)">
<div class="error">
密码强度不够
</div>
</div>
<div class="form-item">
<div class="select clearfix">
<div class="select-item">
<div class="title">
中国大陆
</div>
<ul>
<li>Lorem.</li>
<li>Nemo!</li>
<li>Nobis.</li>
<li>Porro.</li>
<li>Eum.</li>
<li>Nisi!</li>
<li>Unde!</li>
<li>Esse!</li>
<li>Eveniet.</li>
<li>Consectetur!</li>
</ul>
</div>
<div class="input">
<input type="text" placeholder="填写常用的手机号">
</div>
</div>
</div>
<div class="form-item">
<input type="text" placeholder="请输入短信验证码">
<button class="sncode" type="button">点击获取</button>
</div>
<div class="readme">
<label>
<input type="checkbox">
<span class="checkbox"></span>
<span>我已同意</span>
<a href="">《bilibili弹幕网用户使用协议》</a>
和
<a href="">《bilibili弹幕网账号中心规范》</a>
</label>
</div>
<div class="form-item">
<button class="fill">注册</button>
<!-- <button class="fill" disabled>注册</button> -->
</div>
<div class="tip">
<a href="">已有账号,直接登陆></a>
</div>
</div>
</div>
</body>
</html>
结果展示
怎么样,是不是感受到了前端学习的魅力呢,任何一个复杂的网站,都是由我们学过的一些知识灵活结合而成的,我们在学习的过程中,要不断的进行相关的练习,熟练掌握各种技巧,就可以实现网站的设计。
总结
本节博客结束后,我们关于HTML的部分就彻底结束了,接下来会不定期(可能会是两天一更,也可能是三天一更)更新关于CSS进阶部分的内容,敬请期待。