乐闻世界logo
搜索文章和话题

How do I stop Chrome from yellowing my site's input boxes?

1个答案

1

In certain cases, when Chrome automatically fills out forms, the input box background turns yellow, which may clash with the website's design theme. To avoid this, we can change the default behavior using CSS. Here is a common method:

css
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus, input:-webkit-autofill:active { transition: background-color 5000s ease-in-out 0s; -webkit-text-fill-color: #fff !important; }

This CSS code extends the transition time for the background color change, making it appear as if no change has occurred. The -webkit-text-fill-color property is used to adjust the text color, ensuring it remains consistent regardless of the browser's autofill functionality.

Additionally, if you wish to prevent the browser from enabling autofill for specific forms, add the autocomplete="off" attribute to the <input> tag. For example:

html
<input type="text" name="user_name" autocomplete="off">

This instructs the browser not to autofill the input box, thereby avoiding the background color change. However, browser support for autocomplete="off" is not always reliable, so it is recommended to also implement the CSS method to ensure the desired effect.

In summary, by combining CSS styles and HTML attributes, you can effectively prevent Chrome from altering the input box background during autofill, maintaining the website's design consistency and visual appeal.

2024年8月14日 13:58 回复

你的答案