如何在html中使用field-wrap标签添加复选框?

时间:2019-03-12 10:37:57

标签: javascript html css

我正尝试使用field-wrap标签添加检查,但是空格提交按钮和复选框未对齐。我必须以两种形式进行注册和登录。注册表单包含许多字段,例如名称,电子邮件,密码等。使用注册表单中的复选框对条款和条件进行了尝试,但对齐混乱。

*, *:before, *:after {
  box-sizing: border-box;
}

html {
  overflow-y: scroll;
}

body {
  background: #fff;
  font-family: 'Titillium Web', sans-serif;
}

a {
  text-decoration: none;
  color: #4F5459;
  transition: .5s ease;
}
a:hover {
  color: #71D72C;
}

.form .forgot p {

  color: #4F5459;

}

.form {
  background: #fff;
  padding: 40px;
  max-width: 500px;
  margin: 30px auto;
  border-radius: 4px;
  /* box-shadow: 0 4px 10px 4px rgba(19, 35, 47, 0.3); */
}

.tab-group {
  list-style: none;
  padding: 0;
  margin: 0 0 30px 0;
  height: 50%;
}
.tab-group:after {
  content: "";
  display: table;
  clear: both;
}
.tab-group li a {
  display: block;
  text-decoration: none;
  padding: 15px;
  background: #4F5459;
  color: #fff;
  font-size: 20px;
  float: left;
  width: 50%;
  text-align: center;
  cursor: pointer;
  transition: .5s ease;
}
.tab-group li a:hover {
  background: #71D72C;
  color: #ffffff;
}
.tab-group .active a {
  background: #71D72C;
  color: #ffffff;
}

.tab-content > div:last-child {
  display: none;
}

h1 {
  text-align: center;
  color: #4F5459;
  font-weight: 300;
  margin: 0 0 30px;
}

label {
  position: absolute;
  -webkit-transform: translateY(6px);
          transform: translateY(6px);
  left: 14px;
  color: #4F5459;
  transition: all 0.25s ease;
  -webkit-backface-visibility: hidden;
  pointer-events: none;
  font-size: 14px;
}
label .req {
  margin: 2px;
  color: #4F5459;
}

label.active {
  -webkit-transform: translateY(35px);
          transform: translateY(35px);
  left: 2px;
  font-size: 14px;
}
label.active .req {
  opacity: 0;
}

label.highlight {
  color: #4F5459;
  font-size: 14px;
}

input, textarea {
  font-size: 15px;
  display: block;
  width: 100%;
  height: 100%;
  padding: 5px 10px;
  background: #E7E8E6;
  background-image: none;
  border: 1px solid #a0b3b0;
  color: #4F5459;
  border-radius: 0;
  transition: border-color .25s ease, box-shadow .25s ease;
}
input:focus, textarea:focus {
  outline: 0;
  border-color: #71D72C;
}



textarea {
  border: 2px solid #a0b3b0;
  resize: vertical;
}

.field-wrap {
  position: relative;
  margin-bottom: 30px;
}

.top-row:after {
  content: "";
  display: table;
  clear: both;
}
.top-row > div {
  float: left;
  width: 48%;
  margin-right: 4%;
}
.top-row > div:last-child {
  margin: 0;
}

.button {
  border: 0;
  outline: none;
  border-radius: 0;
  padding: 15px 0;
  font-size: 20px;
  font-weight: 300;
  /* text-transform: uppercase; */
  letter-spacing: .1em;
  background: #71D72C;
  color: #ffffff;
  transition: all 0.5s ease;
  -webkit-appearance: none;
}
.button:hover, .button:focus {
  background: #71D72C;
}

.button-block {
  display: block;
  width: 100%;
}

.forgot {
  margin-top: -20px;
  text-align: right;
}
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Sign-Up/Login Form</title>
  <link href='https://fonts.googleapis.com/css?family=Titillium+Web:400,300,600' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div class="form">
      
      <ul class="tab-group">
        <li class="tab active"><a href="#signup">Sign Up</a></li>
        <li class="tab"><a href="#login">Log In</a></li>
      </ul>
      
      <div class="tab-content">
        <div id="signup">   
          <!-- <h1>Sign Up for Free</h1> -->
          
          <form action="/" method="post">
          
          <div class="top-row">
            <div class="field-wrap">
              <label>
                First Name<span class="req">*</span>
              </label>
              <input type="text" required autocomplete="off" />
            </div>
        
            <div class="field-wrap">
              <label>
                Last Name<span class="req">*</span>
              </label>
              <input type="text"required autocomplete="off"/>
            </div>
          </div>

          <div class="field-wrap">
            <label>
              Email Address<span class="req">*</span>
            </label>
            <input type="email"required autocomplete="off"/>
          </div>
          
          <div class="field-wrap">
            <label>
              Password<span class="req">*</span>
            </label>
            <input type="password"required autocomplete="off"/>
          </div>
          <div class="field-wrap">
            <label>
              Business Name<span class="req">*</span>
            </label>
            <input type="text"required autocomplete="off"/>
          </div>
          <h1 style="font-size:14px; text-align: left; font-weight: 600">Payment</h1>

          <div class="field-wrap">
              <label>
                  Name on Card<span class="req">*</span>
              </label>
              <input type="text"required autocomplete="off"/>
            </div>
            <div class="field-wrap">
                <label>
                    Card Number<span class="req">*</span>
                </label>
                <input type="number"required autocomplete="off"/>
              </div>
          <div class="top-row">

              <h1 style="font-size:14px; text-align: left; font-weight: 600">Expiration</h1>

          <div class="field-wrap">

            <label>
             MM<span class="req">*</span>
            </label>
            <input type="text"required autocomplete="off"/>
          </div>


            <div class="field-wrap">
                <label>
                 YYYY<span class="req">*</span>
                </label>
                <input type="text"required autocomplete="off"/>
              </div>

          </div>
          <div class="field-wrap">
              <label>
               CVC<span class="req">*</span>
              </label>
              <input type="text"required autocomplete="off"/>
            </div>

            <div class="field-wrap">
                <label><input type="checkbox" />Option 1</label>

              <!-- <input type="checkbox" required autocomplete="off" /> -->
            <!-- <input type="checkbox" class="form-check-input" id="exampleCheck1" required autocomplete="off"> -->
             <!-- <label class="req form-check-label" for="exampleCheck1">Check me out</label> -->
             </div>


          <button type="submit" class="button button-block"/>Sign Up</button>
          
          </form>

        </div>
        
        <div id="login">   
          <!-- <h1>Welcome Back!</h1> -->
          
          <form action="/" method="post">
          
            <div class="field-wrap">
            <label>
              Email Address<span class="req">*</span>
            </label>
            <input type="email"required autocomplete="off"/>
          </div>
          
          <div class="field-wrap">
            <label>
              Password<span class="req">*</span>
            </label>
            <input type="password"required autocomplete="off"/>
          </div>
          
          <p class="forgot"><a href="#">Forgot Password?</a></p>
          
          <button class="button button-block"/>Log In</button>
          
          </form>

        </div>
        
      </div><!-- tab-content -->
      
</div> <!-- /form -->
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

从摘要中可以看到复选框和提交按钮未对齐。如何使用正确的空格添加类似于上面输入字段的复选框?

1 个答案:

答案 0 :(得分:1)

您已经为输入编码了CSS,因此对于所有输入元素,将需要width:100%height:100%等...

查看随附的代码段

*, *:before, *:after {
  box-sizing: border-box;
}

html {
  overflow-y: scroll;
}

body {
  background: #fff;
  font-family: 'Titillium Web', sans-serif;
}

a {
  text-decoration: none;
  color: #4F5459;
  transition: .5s ease;
}
a:hover {
  color: #71D72C;
}

.form .forgot p {

  color: #4F5459;

}

.form {
  background: #fff;
  padding: 40px;
  max-width: 500px;
  margin: 30px auto;
  border-radius: 4px;
  /* box-shadow: 0 4px 10px 4px rgba(19, 35, 47, 0.3); */
}

.tab-group {
  list-style: none;
  padding: 0;
  margin: 0 0 30px 0;
  height: 50%;
}
.tab-group:after {
  content: "";
  display: table;
  clear: both;
}
.tab-group li a {
  display: block;
  text-decoration: none;
  padding: 15px;
  background: #4F5459;
  color: #fff;
  font-size: 20px;
  float: left;
  width: 50%;
  text-align: center;
  cursor: pointer;
  transition: .5s ease;
}
.tab-group li a:hover {
  background: #71D72C;
  color: #ffffff;
}
.tab-group .active a {
  background: #71D72C;
  color: #ffffff;
}

.tab-content > div:last-child {
  display: none;
}

h1 {
  text-align: center;
  color: #4F5459;
  font-weight: 300;
  margin: 0 0 30px;
}

label {
/*  position: absolute;
  -webkit-transform: translateY(6px);
   transform: translateY(6px);
  left: 14px;
  pointer-events: none;*/
  color: #4F5459;
  transition: all 0.25s ease;
  -webkit-backface-visibility: hidden;
  font-size: 14px;
}
label .req {
  margin: 2px;
  color: #4F5459;
}

label.active {
  -webkit-transform: translateY(35px);
          transform: translateY(35px);
  left: 2px;
  font-size: 14px;
}
label.active .req {
  opacity: 0;
}

label.highlight {
  color: #4F5459;
  font-size: 14px;
}

input, textarea {
  font-size: 15px;
  display: block;
  width: 100%;
  height: 100%;
  padding: 5px 10px;
  background: #E7E8E6;
  background-image: none;
  border: 1px solid #a0b3b0;
  color: #4F5459;
  border-radius: 0;
  transition: border-color .25s ease, box-shadow .25s ease;
}
input:focus, textarea:focus {
  outline: 0;
  border-color: #71D72C;
}
[type=checkbox], [type=radio] {
    box-sizing: border-box;
    padding: 0;
    width: 20px;
    height: 20px;
    display: inline;
    vertical-align: middle;
}


textarea {
  border: 2px solid #a0b3b0;
  resize: vertical;
}

.field-wrap {
  position: relative;
  margin-bottom: 30px;
}

.top-row:after {
  content: "";
  display: table;
  clear: both;
}
.top-row > div {
  float: left;
  width: 48%;
  margin-right: 4%;
}
.top-row > div:last-child {
  margin: 0;
}

.button {
  border: 0;
  outline: none;
  border-radius: 0;
  padding: 15px 0;
  font-size: 20px;
  font-weight: 300;
  /* text-transform: uppercase; */
  letter-spacing: .1em;
  background: #71D72C;
  color: #ffffff;
  transition: all 0.5s ease;
  -webkit-appearance: none;
}
.button:hover, .button:focus {
  background: #71D72C;
}

.button-block {
  display: block;
  width: 100%;
}

.forgot {
  margin-top: -20px;
  text-align: right;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css" rel="stylesheet"/>

<div class="form">
  <ul class="tab-group">
    <li class="tab active"><a href="#signup">Sign Up</a></li>
    <li class="tab"><a href="#login">Log In</a></li>
  </ul>
  <div class="tab-content">
    <div id="signup"> 
      <!-- <h1>Sign Up for Free</h1> -->
      
      <form action="/" method="post">
        <div class="top-row">
          <div class="field-wrap">
            <label> First Name<span class="req">*</span> </label>
            <input type="text" required autocomplete="off" />
          </div>
          <div class="field-wrap">
            <label> Last Name<span class="req">*</span> </label>
            <input type="text" required autocomplete="off"/>
          </div>
        </div>
        <div class="field-wrap">
          <label> Email Address<span class="req">*</span> </label>
          <input type="email" required autocomplete="off"/>
        </div>
        <div class="field-wrap">
          <label> Password<span class="req">*</span> </label>
          <input type="password" required autocomplete="off"/>
        </div>
        <div class="field-wrap">
          <label> Business Name<span class="req">*</span> </label>
          <input type="text" required autocomplete="off"/>
        </div>
        <h1 style="font-size:14px; text-align: left; font-weight: 600">Payment</h1>
        <div class="field-wrap">
          <label> Name on Card<span class="req">*</span> </label>
          <input type="text" required autocomplete="off"/>
        </div>
        <div class="field-wrap">
          <label> Card Number<span class="req">*</span> </label>
          <input type="number" required autocomplete="off"/>
        </div>
        <div class="top-row">
          <h1 style="font-size:14px; text-align: left; font-weight: 600">Expiration</h1>
          <div class="field-wrap">
            <label> MM<span class="req">*</span> </label>
            <input type="text" required autocomplete="off"/>
          </div>
          <div class="field-wrap">
            <label> YYYY<span class="req">*</span> </label>
            <input type="text" required autocomplete="off"/>
          </div>
        </div>
        <div class="field-wrap">
          <label> CVC<span class="req">*</span> </label>
          <input type="text" required autocomplete="off"/>
        </div>
        <div class="field-wrap">
          <label>
            <input type="checkbox" >
            Option 1</label>
          
          <!-- <input type="checkbox" required autocomplete="off" /> --> 
          <!-- <input type="checkbox" class="form-check-input" id="exampleCheck1" required autocomplete="off"> --> 
          <!-- <label class="req form-check-label" for="exampleCheck1">Check me out</label> --> 
        </div>
        <button type="submit" class="button button-block">Sign Up</button>
      </form>
    </div>
    <div id="login"> 
      <!-- <h1>Welcome Back!</h1> -->
      
      <form action="/" method="post">
        <div class="field-wrap">
          <label> Email Address<span class="req">*</span> </label>
          <input type="email" required autocomplete="off"/>
        </div>
        <div class="field-wrap">
          <label> Password<span class="req">*</span> </label>
          <input type="password" required autocomplete="off"/>
        </div>
        <p class="forgot"><a href="#">Forgot Password?</a></p>
        <button class="button button-block">Log In</button>
      </form>
    </div>
  </div>
  <!-- tab-content --> 
  
</div>
<!-- /form -->