如何创建:登录表单
学习如何使用 CSS 创建一个响应式登录表单。
点击按钮可打开登录表单:
如何创建登录表单
第一步 - 添加 HTML:
在容器中添加一张图片,并为每个字段添加输入控件(并带有匹配的标签)。用 <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>
ဒုတိယပုံ - အခြေအနေ CSS ထပ်ပေါင်းပါ
/* 有边框的表单 */ 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%; } }
如何创建模态登录表单
第一步 - 添加 HTML:
<!-- 打开模式登录表单的按钮 --> <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>
ဒုတိယပုံ - အခြေအနေ CSS ထပ်ပေါင်းပါ
/* အပုံအရိုး(အခြေအနေ) */ .modal { display: none; /* လုံးဝကျော်ကျော် */ position: fixed; /* အခြေခံအရာအတွက် အချိန်ချိန်မှား */ z-index: 1; /* အပြင်းအထား 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 အသုံးပြု