如何做 - 登錄檔單
瞭解如何使用 CSS 建立響應式登錄檔單。
點選按鈕開啟登錄檔單
×
如何建立登錄檔單
步驟 1) 新增 HTML
使用 <form> 元素來處理輸入。您可以在我們的PHP教程中瞭解更多關於這方面的資訊。然後為每個欄位新增輸入(帶有匹配的標籤)
示例
<form action="action_page.php" style="border:1px solid #ccc">
<div class="container">
<h1>註冊</h1>
<p>請填寫此表單以建立賬戶。</p>
<hr>
<label for="email"><b>郵箱</b></label>
<input type="text" placeholder="輸入郵箱" name="email" required>
<label for="psw"><b>密碼</b></label>
<input type="password" placeholder="輸入密碼" name="psw" required>
<label for="psw-repeat"><b>重複密碼</b></label>
<input type="password" placeholder="重複密碼" name="psw-repeat" required>
<label>
<input type="checkbox" checked="checked" name="remember" style="margin-bottom:15px"> 記住我
</label>
<p>建立賬戶即表示您同意我們的條款與隱私。</p>
<div class="clearfix">
<button type="button" class="cancelbtn">取消</button>
<button type="submit" class="signupbtn">註冊</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: #04AA6D;
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'">註冊</button>
<!-- The Modal (contains the Sign Up form) -->
<div id="id01" class="modal">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="關閉模態框">times;</span>
<form class="modal-content" action="/action_page.php">
<div class="container">
<h1>註冊</h1>
<p>請填寫此表單以建立賬戶。</p>
<hr>
<label for="email"><b>郵箱</b></label>
<input type="text" placeholder="輸入郵箱" name="email" required>
<label for="psw"><b>密碼</b></label>
<input type="password" placeholder="輸入密碼" name="psw" required>
<label for="psw-repeat"><b>重複密碼</b></label>
<input type="password" placeholder="重複密碼" name="psw-repeat" required>
<label>
<input type="checkbox" checked="checked" name="remember" style="margin-bottom:15px"> 記住我
</label>
<p>建立賬戶即表示您同意我們的條款與隱私。</p>
<div class="clearfix">
<button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">取消</button>
<button type="submit" class="signup">註冊</button>
</div>
</div>
</form>
</div>
步驟 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: #04AA6D;
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 表單教程 瞭解更多關於如何設定表單元素樣式的資訊。