报名表单

创建于 2024-12-03 / 25
字体: [默认] [大] [更大]

了解如何使用 CSS 创建响应式报名表单。


点击按钮打开报名表单:

×

Please fill in this form to create an account.


By creating an account you agree to our Terms & Privacy.


亲自试一试 »


如何创建报名表单

步骤 1) 添加 HTML:

使用 <form> 元素来处理输入。 您可以在我们的 PHP 教程中了解更多信息。 然后为每个字段添加输入(带有匹配的标签):

实例

<form action="action_page.php" style="border:1px solid #ccc">
  <div class="container">
    <h1>Sign Up</h1>
    <p>Please fill in this form to create an account.</p>
    <hr>

    <label for="email"><b>Email</b></label>
    <input type="text" placeholder="Enter Email" name="email" required>

    <label for="psw"><b>Password</b></label>
    <input type="password" placeholder="Enter Password" name="psw" required>

    <label for="psw-repeat"><b>Repeat Password</b></label>
    <input type="password" placeholder="Repeat Password" name="psw-repeat" required>

    <label>
      <input type="checkbox" checked="checked" name="remember" style="margin-bottom:15px"> Remember me
    </label>

    <p>By creating an account you agree to our <a href="#" style="color:dodgerblue">Terms & Privacy</a>.</p>

    <div class="clearfix">
      <button type="button" class="cancelbtn">Cancel</button>
      <button type="submit" class="signupbtn">Sign Up</button>
    </div>
  </div>
</form>
步骤 2) 添加 CSS:

实例

* {box-sizing: border-box}

/* 全角输入字段 */
  input[type=text], input[type=password] {
  width: 100%;
  padding: 15px;
  margin: 5px 0 22px 0;
  display: inline-block;
  border: none;
  background: #f1f1f1;
}

input[type=text]:focus, input[type=password]:focus {
  background-color: #ddd;
  outline: none;
}

hr {
  border: 1px solid #f1f1f1;
  margin-bottom: 25px;
}

/* 为所有按钮设置样式 */
button {
  background-color: #4CAF50;
  color: white;
  padding: 14px 20px;
  margin: 8px 0;
  border: none;
  cursor: pointer;
  width: 100%;
  opacity: 0.9;
}

button:hover {
  opacity:1;
}

/* 取消按钮的额外样式 */
.cancelbtn {
  padding: 14px 20px;
  background-color: #f44336;
}

/* 浮动取消和注册按钮并添加等宽 */
.cancelbtn, .signupbtn {
  float: left;
  width: 50%;
}

/* 为容器元素添加填充 */
.container {
  padding: 16px;
}

/* 清除浮动 */
.clearfix::after {
  content: "";
  clear: both;
  display: table;
}

/* 更改超小屏幕上取消按钮和注册按钮的样式 */
@media screen and (max-width: 300px) {
  .cancelbtn, .signupbtn {
    width: 100%;
  }
} 亲自试一试 »

如何创建模式报名表单

步骤 1) 添加 HTML:

使用 <form> 元素来处理输入。 您可以在我们的 PHP 教程中了解更多信息。 然后为每个字段添加输入(带有匹配的标签):

实例

<!-- 打开模态的按钮 -->
<button onclick="document.getElementById('id01').style.display='block'">Sign Up</button>

<!-- 模式(包含报名表单) -->
<div id="id01" class="modal">
  <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">times;</span>
  <form class="modal-content" action="/action_page.php">
    <div class="container">
      <h1>Sign Up</h1>
      <p>Please fill in this form to create an account.</p>
      <hr>
      <label for="email"><b>Email</b></label>
      <input type="text" placeholder="Enter Email" name="email" required>

      <label for="psw"><b>Password</b></label>
      <input type="password" placeholder="Enter Password" name="psw" required>

      <label for="psw-repeat"><b>Repeat Password</b></label>
      <input type="password" placeholder="Repeat Password" name="psw-repeat" required>

      <label>
        <input type="checkbox" checked="checked" name="remember" style="margin-bottom:15px"> Remember me
      </label>

      <p>By creating an account you agree to our <a href="#" style="color:dodgerblue">Terms & Privacy</a>.</p>

      <div class="clearfix">
        <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">Cancel</button>
        <button type="submit" class="signup">Sign Up</button>
      </div>
    </div>
  </form>
</div>
Advertisement

-->
步骤 2) 添加 CSS:

实例

* {box-sizing: border-box}
/* 全宽输入字段 */
  input[type=text], input[type=password] {
  width: 100%;
  padding: 15px;
  margin: 5px 0 22px 0;
  display: inline-block;
  border: none;
  background: #f1f1f1;
}

/* 当输入获得焦点时添加背景颜色 */
input[type=text]:focus, input[type=password]:focus {
  background-color: #ddd;
  outline: none;
}

/* 为所有按钮设置样式 */
button {
  background-color: #4CAF50;
  color: white;
  padding: 14px 20px;
  margin: 8px 0;
  border: none;
  cursor: pointer;
  width: 100%;
  opacity: 0.9;
}

button:hover {
  opacity:1;
}

/* 取消按钮的额外样式 */
.cancelbtn {
  padding: 14px 20px;
  background-color: #f44336;
}

/* 浮动取消和注册按钮并添加等宽 */
.cancelbtn, .signupbtn {
  float: left;
  width: 50%;
}

/* 为容器元素添加填充 */
.container {
  padding: 16px;
}

/* 模态(背景) */
.modal {
  display: none; /* 默认隐藏 */
  position: fixed; /* 原地不动 */
  z-index: 1; /* 保持在顶部 */
  left: 0;
  top: 0;
  width: 100%; /* 全宽 */
  height: 100%; /* 全高 */
  overflow: auto; /* 如果需要,启用滚动 */
  background-color: #474e5d;
  padding-top: 50px;
}

/* 模态内容/框 */
.modal-content {
  background-color: #fefefe;
  margin: 5% auto 15% auto; /* 从顶部开始 5%,从底部开始 15% 并居中 */
  border: 1px solid #888;
  width: 80%; /* 可能或多或少,取决于屏幕大小 */
}

/* 设置水平尺样式 */
hr {
  border: 1px solid #f1f1f1;
  margin-bottom: 25px;
}

/* 关闭按钮 (x) */
.close {
  position: absolute;
  right: 35px;
  top: 15px;
  font-size: 40px;
  font-weight: bold;
  color: #f1f1f1;
}

.close:hover,
.close:focus {
  color: #f44336;
  cursor: pointer;
}

/* 清除浮动 */
.clearfix::after {
  content: "";
  clear: both;
  display: table;
}

/* 更改超小屏幕上取消按钮和注册按钮的样式 */
@media screen and (max-width: 300px) {
  .cancelbtn, .signupbtn {
    width: 100%;
  }
}

提示:您还可以使用以下 javascript 通过单击模式内容外部来关闭模式(而不仅仅是使用"x"或"取消"按钮来关闭它):

实例

<script>
// 获取模态
var modal = document.getElementById('id01');

// 当用户点击模态框外的任意位置时,关闭它
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}
</script> 亲自试一试 »

提示:转到我们的HTML 表单教程,了解有关 HTML 表单的更多信息。

提示:请转到我们的CSS 表单教程,了解有关如何设置表单元素样式的更多信息。



0 人点赞过