萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> Div CSS 教學

CSS 實現輸入框無邊框底線風格(網頁填空題適用)

核心 CSS

.underline-input {
  border: none;
  border-bottom: 1px solid #333; /* 僅保留底線 */
  background: transparent;
  outline: none;
  padding: 4px 2px;
  font-size: 16px;
  width: 200px;
}
.underline-input:focus {
  border-bottom-color: #0066cc;
}

HTML 範例

<p>用戶名:<input type="text" name="username" class="underline-input"></p>
<p>密碼:<input type="password" name="pwd" class="underline-input"></p>

進階變體

  • 動畫底線:transition: border-color .2s, box-shadow .2s; + box-shadow: 0 1px 0 0 currentColor;
  • Material Design 風:偽元素畫底線,焦點時寬度從 0 擴展到 100%。
  • 唯讀/禁用態::read-only { border-bottom-style: dashed; color: #999; }

無障礙提醒

保留 :focus 明顯樣式,確保鍵盤使用者能識別焦點位置;勿移除 outline 除非提供等效替代指示器。

copyright © 萬盛學電腦網 all rights reserved