如何创建:登录表单

学习如何使用 CSS 创建一个响应式登录表单。

点击按钮可打开登录表单:

ਸਵੈ ਮੰਗਲਾ ਕਰੋ

如何创建登录表单

ਕਦਮ ਪਹਿਲਾ - ਐੱਚਟੀਐੱਮਐੱਲ ਜੋੜੋ:

在容器中添加一张图片,并为每个字添加输入控件(并带有匹配的标签)。用 <form> 元素将它们包裹起来,以处理输入。

您可以在我们的 PHP 教程 中了解更多关于如何处理输入的信息。

<form action="action_page.php" method="post">
  <div class="imgcontainer">
    <img src="img_avatar2.png" alt="Avatar" class="avatar">
  </div>
  <div class="container">
    <label for="uname"><b>ਉਪਭੋਗਤਾ ਨਾਮ</b></label>
    <input type="text" placeholder="ਉਪਭੋਗਤਾ ਨਾਮ ਲਿਖੋ" name="uname" required>
    <label for="psw"><b>ਪਾਸਵਰਡ</b></label>
    <input type="password" placeholder="ਪਾਸਵਰਡ ਲਿਖੋ" name="psw" required>
    <button type="submit">ਲਾਗਇਨ</button>
    <label>
      <input type="checkbox" checked="checked" name="remember"> ਮੈਨੂੰ ਯਾਦ ਰੱਖੋ
    </label>
  </div>
  <div class="container" style="background-color:#f1f1f1">
    <button type="button" class="cancelbtn">Cancel</button>
    <span class="psw">ਪਾਸਵਰਡ ਭੁਲਾ ਦਿੱਤਾ? <a href="#">ਪਾਸਵਰਡ ਲੈਓ?</a></span>
  </div>
</form>

ਦੂਜਾ ਕਦਮ - ਐੱਸਐੱਸਸੀ ਜੋੜੋ:

/* 有边框的表单 */
form {
  border: 3px solid #f1f1f1;
}
/* 全宽输入框 */
input[type=text], input[type=password] {
  width: 100%;
  padding: 12px 20px;
  margin: 8px 0;
  display: inline-block;
  border: 1px solid #ccc;
  box-sizing: border-box;
}
/* 为所有按钮设置样式 */
button {
  background-color: #04AA6D;
  color: white;
  padding: 14px 20px;
  margin: 8px 0;
  border: none;
  cursor: pointer;
  width: 100%;
}
/* ਬਟਨ ਉੱਪਰ ਲੱਗਣ ਲਈ ਇਸ਼ਤਿਹਾਰ ਕਰੋ */
button:hover {
  opacity: 0.8;
}
/* ਰਦੂਆ ਬਟਨ ਦੇ ਅਦਾਰਾ ਸਟਾਈਲ (ਲਾਲ) */
.cancelbtn {
  width: auto;
  padding: 10px 18px;
  background-color: #f44336;
}
/* ਇਸ ਕੰਟੇਨਰ ਵਿੱਚ ਆਵਾਜਾਈ ਚਿੱਤਰ ਨੂੰ ਮੱਧਮ ਕਰੋ */
.imgcontainer {
  text-align: center;
  margin: 24px 0 12px 0;
}
/* ਆਵਾਜਾਈ ਚਿੱਤਰ */
img.avatar {
  width: 40%;
  border-radius: 50%;
}
/* ਕੰਟੇਨਰ ਵਿੱਚ ਅੰਦਰੂਨੀ ਪੈਡਿੰਗ ਜੋੜੋ */
.container {
  padding: 16px;
}
/* "Forgot password" ਟੈਕਸਟ */
span.psw {
  float: right;
  padding-top: 16px;
}
/* ਸੂਕਸ਼ਮ ਸਕ੍ਰੀਨ ਉੱਤੇ span ਅਤੇ ਰਦੂਆ ਬਟਨ ਦੇ ਸਟਾਈਲ ਬਦਲਣਾ */
@media screen and (max-width: 300px) {
  span.psw {
    display: block;
    float: none;
  }
  .cancelbtn {
    width: 100%;
  }
}

ਸਵੈ ਮੰਗਲਾ ਕਰੋ

ਮੋਡਲ ਲਾਗਇਨ ਫਾਰਮ ਕਿਵੇਂ ਬਣਾਓ

ਕਦਮ ਪਹਿਲਾ - ਐੱਚਟੀਐੱਮਐੱਲ ਜੋੜੋ:

<!-- 打开模式登录表单的按钮 -->
<button onclick="document.getElementById('id01').style.display='block'">Login</button>
<!-- 模态 -->
<div id="id01" class="modal">
  <span onclick="document.getElementById('id01').style.display='none'"
class="close" title="Close Modal">×</span>
  <!-- 模态内容 -->
  <form class="modal-content animate" action="/action_page.php">
    <div class="imgcontainer">
      <img src="img_avatar2.png" alt="Avatar" class="avatar">
    </div>
    <div class="container">
      <label for="uname"><b>ਉਪਭੋਗਤਾ ਨਾਮ</b></label>
      <input type="text" placeholder="ਉਪਭੋਗਤਾ ਨਾਮ ਲਿਖੋ" name="uname" required>
      <label for="psw"><b>ਪਾਸਵਰਡ</b></label>
      <input type="password" placeholder="ਪਾਸਵਰਡ ਲਿਖੋ" name="psw" required>
      <button type="submit">ਲਾਗਇਨ</button>
      <label>
        <input type="checkbox" checked="checked" name="remember"> ਮੈਨੂੰ ਯਾਦ ਰੱਖੋ
      </label>
    </div>
    <div class="container" style="background-color:#f1f1f1">
      <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">ਰੱਦ ਕਰੋ</button>
      <span class="psw">ਪਾਸਵਰਡ ਭੁਲਾ ਦਿੱਤਾ? <a href="#">ਪਾਸਵਰਡ ਲੈਓ?</a></span>
    </div>
  </form>
</div>

ਦੂਜਾ ਕਦਮ - ਐੱਸਐੱਸਸੀ ਜੋੜੋ:

/* ਮੋਡਲ (ਪਿੱਟੇ) */
.modal {
  display: none; /* ਮੂਲਤਬੀ ਛੁਪਾਓ */
  position: fixed; /* ਮੌਜੂਦਾ ਥਾਂ ਰੱਖੋ */
  z-index: 1; /* ਉੱਪਰ ਰੱਖੋ */
  left: 0;
  top: 0;
  width: 100%; /* ਪੂਰੀ ਚੌਡਾਈ */
  height: 100%; /* ਪੂਰੀ ਉਚਾਈ */
  overflow: auto; /* ਜੇਕਰ ਜ਼ਰੂਰਤ ਹੈ ਤਾਂ ਸਰਕਲ ਚਾਲੂ ਕਰੋ */
  background-color: rgb(0,0,0); /* ਵਾਪਸ ਰੰਗ */
  background-color: rgba(0,0,0,0.4); /* ਕਾਲਾ ਪਾਰਦਰਸ਼ੀ */
  padding-top: 60px;
}
/* ਮੋਡਲ ਕੰਟੈਂਟ/ਫੈਨ */
.modal-content {
  background-color: #fefefe;
  margin: 5px auto; /* ਉੱਪਰ ਦੇ 15% ਵਿੱਚ ਅਤੇ ਸੈਂਟਰ ਵਿੱਚ */
  border: 1px solid #888;
  width: 80%; /* ਸਕਰੀਨ ਸਾਈਜ਼ ਨਾਲ ਸਬੰਧਤ, ਸ਼ਾਇਦ ਕੁਝ ਹੋਰ ਹੋਵੇ */
}
/* ਬੰਦ ਬਟਨ */
.close {
  /* ਇਸਨੂੰ ਮੋਡਲ ਫੈਨ ਬਾਹਰ ਦੇ ਉੱਪਰੋਕਤ ਦਾਹਿਰੇ ਵਿੱਚ ਸਥਿਤ ਕਰੋ */
  position: absolute;
  right: 25px;
  top: 0;
  color: #000;
  font-size: 35px;
  font-weight: bold;
}
/* ਮਹਿੰਗੀ ਵਾਲੇ ਬੰਦ ਬਟਨ */
.close:hover,
.close:focus {
  color: red;
  cursor: pointer;
}
/* ਸਕੇਲ ਐਨੀਮੇਸ਼ਨ ਜੋੜੋ */
.animate {
  -webkit-animation: animatezoom 0.6s;
  animation: animatezoom 0.6s
}
@-webkit-keyframes animatezoom {
  from {-webkit-transform: scale(0)}
  to {-webkit-transform: scale(1)}
}
@keyframes animatezoom {
  from {transform: scale(0)}
  to {transform: scale(1)}
}

ਸੁਝਾਅ:ਤੁਸੀਂ ਹੋਰ ਵੀ ਜਾਵਾਸਕ੍ਰਿਪਟ ਕੋਡ ਵਰਤ ਸਕਦੇ ਹੋ ਕਿ ਮੋਡਲ ਫੈਨਸ ਤੋਂ ਬਾਹਰ ਕਿਸੇ ਥਾਂ ਨੂੰ ਕਲਿੱਕ ਕਰਕੇ ਮੋਡਲ ਫੈਨ ਬੰਦ ਕਰੋ (ਮਾਤਰ "x" ਜਾਂ "cancel" ਬਟਨ ਨਹੀਂ):

<script>
// ਮੋਡਲ ਪ੍ਰਾਪਤ ਕਰੋ
var modal = document.getElementById('id01');
// ਜਦੋਂ ਯੂਜ਼ਰ ਮੋਡਲ ਤੋਂ ਬਾਹਰ ਕਿਸੇ ਥਾਂ ਨੂੰ ਕਲਿੱਕ ਕਰੇ ਤਾਂ ਇਸਨੂੰ ਬੰਦ ਕਰੋ 
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
  }
}
</script>

ਸਵੈ ਮੰਗਲਾ ਕਰੋ

ਸਬੰਧਤ ਪੰਨੇ

ਸਿੱਖਿਆ:HTML 表单

ਸਿੱਖਿਆ:CSS 表单