1. 程式人生 > >Chrome瀏覽器自動填充的表單如何去掉淡黃色背景???

Chrome瀏覽器自動填充的表單如何去掉淡黃色背景???

1、原因:表單自動填充元素在chrome下會有一個預設樣式 (如下),並且優先順序最高,無法覆蓋(!important也無法覆蓋)。

input:-webkit-autofill {     background-color: rgb(250, 255, 189);     background-image: none;     color: rgb(0, 0, 0); }

2、解決方法一:<1>沒有背景圖片的元素

input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0px 1000px white inset;
  -webkit-text-fill-color: #333;
}

<2>有背景圖片的元素--把背景圖片拿出來,獨立成為一個標籤如<label></label>等。

3、解決方法二:關閉瀏覽器自帶填充表單功能

<!-- 對整個表單設定 -->
<form autocomplete="off" method=".." action="..">
<!-- 或對單一元素設定 -->
<input type="text" name="textboxname" autocomplete="off">

4、注:除了chrome預設定義的background-colorbackground-image

color不能用 !important 提升其優先順序以外,其他的屬性均可使用!important提升其優先順序。