The background of the input text box turns yellow when the chrome form is automatically filled. Solution

Source: Internet
Author: User

After the chrome form is automatically filled, the background of the input text box will become yellow. You may encounter this situation. This is because chrome will add input to the automatically filled input form by default: -WebKit-AutoFill: the solution is as follows. If you are interested, you can find out.

Scenario 1: The input text box contains a solid background. 
You can use a solid color shadow large enough for input:-WebKit-AutoFill to overwrite the yellow background of the input box. For example:
The Code is as follows:

Input:-WebKit-AutoFill {

-WebKit-box-Shadow: 0 0 0px 1000px white inset;
Border: 1px solid # CCC! Important;
}

If you use attributes such as rounded corners or find that the length and height of the input box are not quite correct, you can adjust them. Except for the Default background-color, background-image, and color defined by Chrome, they cannot be used! Other attributes except important can be used to increase their priority! Important increases its priority, for example:

The Code is as follows:

Input:-WebKit-AutoFill {
-WebKit-box-Shadow: 0 0 0px 1000px white inset;
Border: 1px solid # CCC! Important;
Height: 27px! Important;
Line-Height: 27px! Important;
Border-radius: 0 4px 4px 0;
}


Scenario 2: The input text box uses the image background. 

This is troublesome. There are currently no perfect solutions. There are two options:
1. If your image background is not complex and you only have some simple inner shadows, you can use the method described above to overwrite the yellow background with a solid color shadow, at this time, the original inner shadow effect is no longer available.
2. If you really want to retain the original inner shadow effect, you can only sacrifice the chrome AutoFill form function and implement it using Js. For example:

The Code is as follows:

$ (Function (){
If (navigator. useragent. tolowercase (). indexof ("Chrome")> = 0 ){
$ (Window). Load (function (){
$ ('Ul input: Not (input [type = submit]) '). Each (function (){
VaR outhtml = This. outerhtml;
$ (This). append (outhtml );
});
});
}
10 .});

The traversal object may need to be adjusted according to your needs. If you don't want to use JS, well, the automatic filling function of the form is disabled directly on the form Tag: AutoComplete = "off ".

Some tests on the failure of the online uploading Method 

This problem has plagued me for a long time. There are two ways to write on the Internet: the first is to rewrite the background-color and color for input:-WebKit-AutoFill in the style, use! Important increases its priority. The second method is to use jquery. First, determine whether it is chrome. If yes, traverse the input:-WebKit-AutoFill element, and perform operations such as value, append, and remove.

However, I found that both methods are ineffective! I don't know whether the current chrome (27) version does not support rewriting the original property of input:-WebKit-AutoFill with the upgrade of chrome version. In addition, JS cannot obtain the value of the form automatically filled by Chrome. Therefore, the method for using jquery on the internet is ineffective, and the yellow background can be removed at most, the automatically filled value is removed. The value of the form automatically filled by Chrome exists in the DIV of documentfragment. If any of the children's shoes knows how to obtain the value of the form automatically filled by Chrome, please kindly advise.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.