Skip to content

表单练习

html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>注册页面</title>
    <link rel="stylesheet" href="css/reset.css" />
    <link rel="stylesheet" href="css/reg.css" />
  </head>

  <body>
    <div class="form">
      <!-- 标题 -->
      <h2 class="title">
        <span>注册</span>
      </h2>
      <!-- 表单区域 -->
      <div class="form-area">
        <!-- 账号 -->
        <div class="form-item has-error">
          <input type="text" placeholder="请输入账号" />
          <div class="error">该昵称已经被他人占用</div>
        </div>
        <!-- 密码 -->
        <div class="form-item has-error">
          <input
            type="password"
            name=""
            id=""
            placeholder="密码(6-16个字符组成,区分大小写)"
          />
          <div class="error">密码强度不够</div>
        </div>
        <!-- 手机号 -->
        <div class="form-item">
          <div class="phone clearfix">
            <div class="area-select">
              <div class="area-name">中国大陆</div>
              <ul>
                <li class="active">中国大陆</li>
                <li>Quis?</li>
                <li>Asperiores!fadfadfaf</li>
                <li>Quod?</li>
                <li>Nobis?</li>
                <li>Ipsam?</li>
                <li>Tempora.</li>
                <li>Qui.</li>
                <li>Laboriosam!</li>
                <li>Fugiat.</li>
                <li>Assumenda!</li>
                <li>Molestias.</li>
                <li>Iusto.</li>
                <li>Neque.</li>
                <li>Magnam.</li>
                <li>Magnam!</li>
                <li>Corporis?</li>
                <li>Quam.</li>
                <li>Sapiente.</li>
                <li>Officia.</li>
                <li>Corporis.</li>
                <li>Pariatur?</li>
                <li>Veniam?</li>
                <li>Recusandae?</li>
                <li>Quaerat?</li>
                <li>Repellendus.</li>
                <li>Voluptatum!</li>
                <li>Eligendi.</li>
                <li>Explicabo!</li>
                <li>Iste?</li>
              </ul>
            </div>
            <input type="text" placeholder="填写常用的手机号" />
          </div>
        </div>
        <!-- 短信验证 -->
        <div class="form-item">
          <div class="message">
            <input type="text" placeholder="请输入短信验证验证码" />
            <button class="btn-sncode">点击获取</button>
          </div>
        </div>
        <!-- 协议 -->
        <div class="read-me">
          <label>
            <input type="checkbox" />
            <span class="checkbox"> </span>
            <span
              >我已同意 <a href="">《哔哩哔哩弹幕网用户使用协议》</a> 和<a
                href=""
                >《哔哩哔哩弹幕网账号中心规范》</a
              >
            </span>
          </label>
        </div>
        <!-- 注册按钮 -->
        <div class="form-item">
          <button class="btn-register" disabled>注册</button>
        </div>
        <!-- 已有账号 -->
        <div class="tip">
          <a href="">已有账号,直接登录&gt;</a>
        </div>
      </div>
    </div>
  </body>
</html>
css
.clearfix::after {
  content: "";
  display: block;
  clear: both;
}
body {
  line-height: 1.5;
}

.form {
  width: 1000px;
  margin: 1em auto;
}

.form .title {
  text-align: center;
  border-bottom: 1px solid #ddd;
  height: 30px;
  margin-bottom: 3em;
}

.form .title span {
  font-size: 38px;
  background-color: #fff;
  padding: 0 10px;
}

/* 统一设置文本框的样式 */

input[type="text"],
input[type="password"] {
  border: 1px solid #dcdfe6;
  width: 100%;
  height: 40px;
  border-radius: 4px;
  text-indent: 1em;
  box-sizing: border-box;
  font-size: 14px;
  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-area {
  width: 430px;
  margin: 0 auto;
}

.form-area .form-item {
  margin: 40px 0;
  position: relative;
}

.form-area .phone .area-select {
  float: left;
  width: 140px;
  height: 40px;
  position: relative;
}

.form-area .form-item .phone input {
  float: left;
  width: 290px;
  height: 40px;
  border-radius: 0 4px 4px 0;
}

.form-area .phone .area-select .area-name {
  height: 40px;
  line-height: 40px;
  padding: 0 20px;
  border: 1px solid #dcdfe6;
  box-sizing: border-box;
  border-radius: 4px 0 0 4px;
  color: #909399;
  cursor: pointer;
  border-right: none;
}

.form-area .phone .area-select ul {
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  width: 100%;
  padding: 10px 0;
  /* 最大高度:内容不够则适应内容高度,内容超过则限制为最大高度 */
  max-height: 300px;
  overflow-y: auto;
  box-sizing: border-box;
  background-color: #fff;
  /* 通过绝对定位和z-index实现溢出元素遮挡后面元素 */
  position: absolute;
  z-index: 1;
  left: 0;
  top: 50px;
  color: #606266;
  font-size: 14px;
  display: none;
}

.form-area .phone .area-select li {
  height: 34px;
  line-height: 34px;
  padding: 0 20px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.form-area .phone .area-select li:hover {
  background-color: #f5f7fa;
}

.form-area .phone .area-select li.active {
  color: #00a1d6;
  font-weight: bold;
}

/* 统一设置按钮样式 */

button {
  background-color: #00a1d6;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  border-radius: 4px;
  height: 40px;
}

button:hover {
  background-color: #33b4de;
}

button:disabled {
  cursor: not-allowed;
  background-color: #f5f5f5;
  color: rgba(0, 0, 0, 0.25);
  box-sizing: border-box;
  border: 1px solid #ccc;
}

/* 短信 */

.form-area .message {
  position: relative;
}

.form-area .message .btn-sncode {
  width: 130px;
  height: 36px;
  position: absolute;
  right: 2px;
  top: 2px;
}

/* 协议 */
.form a {
  color: #00a1d6;
}

.form-area .read-me {
  margin: -30px 0;
  font-size: 12px;
}

.form-area .read-me .checkbox {
  width: 12px;
  height: 12px;
  border: 1px solid #ccc;
  display: inline-block;
  border-radius: 3px;
  cursor: pointer;
  vertical-align: sub;
}

.form-area .read-me input {
  display: none;
}

.form-area .read-me input:checked + .checkbox {
  border: 1px solid #00a1d6;
}

.form-area .read-me input:checked + .checkbox::after {
  content: "";
  width: 7px;
  height: 7px;
  display: block;
  border-radius: 1.5px;
  background-color: #33b4de;
  margin-left: 2.5px;
  margin-top: 2.5px;
}

/* 注册按钮 */

.form .btn-register {
  width: 100%;
}

/* 直接登录 */

.form-area .tip {
  text-align: right;
  font-size: 12px;
  margin-top: -30px;
}

/* 表单错误 */
.form-area .form-item .error {
  color: #f45d90;
  height: 40px;
  line-height: 40px;
  position: absolute;
  width: 240px;
  top: 0;
  right: -250px;
  font-size: 12px;
  display: none;
}

.form-area .form-item.has-error .error {
  display: block;
}

.form-area .form-item.has-error input {
  border-color: #f45d90;
}
css
/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}

/* HTML5 display-role reset for older browsers */
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
  display: block;
}

body {
  line-height: 1;
}

ol,
ul {
  list-style: none;
}

blockquote,
q {
  quotes: none;
}

blockquote:before,
blockquote:after,
q:before,
q:after {
  content: "";
  content: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

a {
  text-decoration: none;
  color: inherit;
}

input,
textarea,
button,
select {
  border: none;
}

input:focus,
textarea:focus,
button:focus,
select:focus {
  outline: none;
  outline-offset: 0;
}