開發者嘗試在 <input> 標籤屬性中直接寫入 CSS:
<input ... background-color: #f2f2f2; />
導致樣式無效,原因是 HTML 標籤屬性不支援直接嵌入 CSS 宣告。
<input type="hidden" id="username" name="username"
value="..." style="background-color: #f2f2f2;" />
<style>
.input-bg-gray { background-color: #f2f2f2; }
</style>
<input type="hidden" id="username" name="username"
value="..." class="input-bg-gray" />
<style>
input[type="hidden"]#username { background-color: #f2f2f2; }
/* 或 */
#username { background-color: #f2f2f2; }
</style>
type="hidden" 的輸入框預設不顯示,背景色僅在開發者工具檢視或動態改為可見時生效color 屬性border、padding 微調<!DOCTYPE html>
<html>
<head>
<style>
.form-input {
background-color: #f2f2f2;
border: 1px solid #ddd;
padding: 8px;
border-radius: 4px;
}
</style>
</head>
<body>
<form>
<input type="text" class="form-input" placeholder="一般輸入框" />
<input type="hidden" id="token" name="token" value="abc123" class="form-input" />
</form>
</body>
</html>