减少模态窗口大小以适应修改CSS的表单字段

时间:2018-12-31 13:22:59

标签: html css

我正在建立一个网页,我需要创建一个注册和登录表格。

我写了所有的html / css代码,但我不明白如何使字段适合表单。我试图修改 .modal-dialog .modal-content CSS,并通过修改.modal-content padding 来减小字段的大小但是周围仍然留有很大的空白。 如何消除空白?

.modal {}

.modal-content {
  padding: 80px;
}

.modal-body input {
  padding: 5px;
  margin-bottom: 30px;
  width: 100%;
  box-sizing: border-box;
  box-shadow: none;
  outline: none;
  border: none;
  border-bottom: 2px solid #999;
}

.modal-body input[type="submit"] {
  border-radius: 25px;
  font-size: 20px;
  height: 40px;
  cursor: pointer;
  background: rgb(255, 69, 0);
  color: #fff;
  margin-bottom: 0;
}

.modal-body input[type="submit"]:hover {
  background: rgb(255, 127, 80);
  color: #fff;
}

.modal-body form div {
  position: relative;
}

.modal-body form div label {
  position: absolute;
  top: 3px;
  pointer-events: none;
  left: 0;
  transition: .5s;
}

.modal-body input:focus~label,
.modal-body input:valid~label {
  left: 0;
  top: -16px;
  color: rgb(169, 169, 169);
  font-size: 12px;
  font-weight: bold;
}

.modal-body input:focus,
.modal-body input:valid {
  border-bottom: 2px solid rgb(169, 169, 169);
}
<!--Nav bar buttons-->
<form>
  <!-- Button trigger modal -->
  <button id="signupBtn" type="button" class="btn btn-primary" data-toggle="modal" data-target="#signupModalBtn">Registrati</button>
  <button id="loginBtn" type="button" class="btn btn-primary" data-toggle="modal" data-target="#loginModalBtn">Log
                        In</button>
</form>

<!-- Modal SignUp-->
<div class="modal fade" id="signupModalBtn" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="contentinfo">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Registrati e inizia ad imparare!</h5>
        <button id="signupCloseBtn" type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
      </div>
      <div class="modal-body">
        <form>
          <div>
            <input type="text" name="Username" required="">
            <label>Username</label>
          </div>
          <div>
            <input type="text" name="First Name" required="">
            <label>First Name</label>
          </div>
          <div>
            <input type="text" name="Second Name" required="">
            <label>Second Name</label>
          </div>
          <div>
            <input type="email" name="Email" required="">
            <label>Email </label>
          </div>
          <div>
            <input type="password" name="Passowrd" required="">
            <label>Password</label>
          </div>
          <div>
            <input type="password" name="Re-Enter Password" required="">
            <label>Re-Enter Password</label>
          </div>
          <input id="singupInternalBtn" type="submit" value="Registrati" name="Submit">
        </form>
      </div>
      <div class="modal-footer">
        <p id="signupBtnTextFooter">Hai già un account?Effettua il Log In!</p>
      </div>
    </div>
  </div>
</div>

我想创建一个注册/登录表单,例如Udemy的表单(谈论尺寸),我将添加一张我现在得到的img!

https://ibb.co/StStxbH

1 个答案:

答案 0 :(得分:2)

尝试在css下面给出,因为modal-dialog需要具有max-width,因此您需要像下面这样设置max-width,

body {
    background: #000;
    padding: 20px;
}

.modal-dialog {
    max-width: 600px;
    background: #FFF;
    margin: auto;
}

.modal-content {
    padding: 20px;
}

.modal {}

.modal-content {
  padding: 80px;
}

.modal-body input {
  padding: 5px;
  margin-bottom: 30px;
  width: 100%;
  box-sizing: border-box;
  box-shadow: none;
  outline: none;
  border: none;
  border-bottom: 2px solid #999;
}

.modal-body input[type="submit"] {
  border-radius: 25px;
  font-size: 20px;
  height: 40px;
  cursor: pointer;
  background: rgb(255, 69, 0);
  color: #fff;
  margin-bottom: 0;
}

.modal-body input[type="submit"]:hover {
  background: rgb(255, 127, 80);
  color: #fff;
}

.modal-body form div {
  position: relative;
}

.modal-body form div label {
  position: absolute;
  top: 3px;
  pointer-events: none;
  left: 0;
  transition: .5s;
}

.modal-body input:focus~label,
.modal-body input:valid~label {
  left: 0;
  top: -16px;
  color: rgb(169, 169, 169);
  font-size: 12px;
  font-weight: bold;
}

.modal-body input:focus,
.modal-body input:valid {
  border-bottom: 2px solid rgb(169, 169, 169);
}
body {
    background: #000;
    padding: 20px;
}

.modal-dialog {
    max-width: 600px;
    background: #FFF;
    margin: auto;
}

.modal-content {
    padding: 20px;
}
<!--Nav bar buttons-->
<form>
  <!-- Button trigger modal -->
  <button id="signupBtn" type="button" class="btn btn-primary" data-toggle="modal" data-target="#signupModalBtn">Registrati</button>
  <button id="loginBtn" type="button" class="btn btn-primary" data-toggle="modal" data-target="#loginModalBtn">Log
                        In</button>
</form>

<!-- Modal SignUp-->
<div class="modal fade" id="signupModalBtn" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="contentinfo">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Registrati e inizia ad imparare!</h5>
        <button id="signupCloseBtn" type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
      </div>
      <div class="modal-body">
        <form>
          <div>
            <input type="text" name="Username" required="">
            <label>Username</label>
          </div>
          <div>
            <input type="text" name="First Name" required="">
            <label>First Name</label>
          </div>
          <div>
            <input type="text" name="Second Name" required="">
            <label>Second Name</label>
          </div>
          <div>
            <input type="email" name="Email" required="">
            <label>Email </label>
          </div>
          <div>
            <input type="password" name="Passowrd" required="">
            <label>Password</label>
          </div>
          <div>
            <input type="password" name="Re-Enter Password" required="">
            <label>Re-Enter Password</label>
          </div>
          <input id="singupInternalBtn" type="submit" value="Registrati" name="Submit">
        </form>
      </div>
      <div class="modal-footer">
        <p id="signupBtnTextFooter">Hai già un account?Effettua il Log In!</p>
      </div>
    </div>
  </div>
</div>