從零構建一個視覺精致、交互豐富的登入表單,展示 CSS3 進階技巧:多重漸變背景、偽元素圖標、@font-face 圖標字體、動態陰影、焦點發光、按鈕按下狀態。
<body>
<div class="content">
<form class="login-form">
<div class="username">
<input type="text" name="username" placeholder="" autocomplete="on" />
<span class="user-icon icon">u</span>
</div>
<div class="password">
<input type="password" name="password" placeholder="" />
<span class="password-icon icon">p</span>
</div>
<div class="account-control">
<input type="checkbox" id="Remember me" name="Remember me" value="Remember me" checked />
<label for="Remember me" class="check" data-on="c"></label>
<label for="Remember me" class="info">Remember me</label>
<button type="submit">Login</button>
</div>
</form>
</div>
</body>
linear-gradient 背景 + box-shadow 立體感 + ::before 放大頭像圓環。::before/::after 造三角形指示器,:focus 觸發邊框發光(box-shadow)、圖標背景漸變變色。input,用 label.check 模擬,:checked + label::before 透過 content:attr(data-on) 顯示圖標字體「c」(打勾)。linear-gradient 疊加實現立體邊框,:hover 發光擴散、:active 漸變反轉按下感。@font-face 載入 .eot/.woff/.ttf/.svg,語意字符 u/p/c 對應用戶/密碼/勾選。
/* 輸入框 focus 發光 */
.login-form .username input:focus,
.login-form .password input:focus {
border-color: rgb(69,153,228);
box-shadow: 0 0 2px 1px rgb(200,223,244);
}
/* 按鈕 hover 發光擴散 */
.login-form button[type="submit"]:hover {
box-shadow: inset 0 1px 0 rgb(86,174,251), 0 0 10px 3px rgba(74,162,241,0.5);
}
/* Checkbox 勾選顯示圖標 */
.login-form .account-control input:checked + label.check:before {
content: attr(data-on); font-family: 'loginform-icon';
}
此範例展示 CSS3 在表單美化上的極致能力,零圖片(除頭像)、零 JS、全靈活可維護。