HTML select box not showing drop-down arrow on android version 4.0 when set with background color

女生的网名这么多〃 提交于 2019-12-17 18:26:21

问题


I need to set the background color for select box as yellow. When i tested,it does show box with yellow color and arrow on android 2.3 and android 3.0.

But on android 4.0 it shows the select as complete yellow without the drop-down arrow.

Any idea how to resolve the issue?

I am designing this with phone-gap.

This is my code where i am setting background-color for html select.

<select style="background-color:#FFFF00;border:#FFFF00;height:25px;font-family:Arial, Helvetica, sans-serif; color:#000000; font-size:14px; font-weight:bold; text-align:center;">
          <option></option>
          <option>1</option>
          <option>2</option>
          <option>3</option>
          <option>4</option>
          <option>5</option>

        </select>

回答1:


The Android Browser's rendering of <select>s is buggy and will remove the normal styling if a background or border is applied.

Since <select>s not looking like <select>s is a pretty big usability issue, your best bet is to not style them for this browser only.

Unfortunately, there's no pure CSS way of selecting/excluding the Android Browser, so I recommend you use Layout Engine (https://github.com/stowball/Layout-Engine), which will add a class of .browser-android to the <html> tag.

You could then style all <select>s except on Android Browser, like so:

html:not(.browser-android) select {
    background: #0f0;
    border: 1px solid #ff0;
}



回答2:


I had this same issue & i was wondering till now why this is happening as it don't not happen on some of the other projects.

While trying to learn more about Bootstrap & Foundation Framework i found the solution on bootstrap as they have raised this problem on some mobile device if we mentioned border or background for the drop-downs.

I am not taking credit from any one but would like to share links of page where it is mentioned & solution is also given

Bootstrap: https://getbootstrap.com/docs/4.0/getting-started/browsers-devices/#select-menu

JS Bin: http://jsbin.com/OyaqoDO/2

I hope this will be useful to other who might face this issue this solution is related to bootstrap. & can me modified to your project needs.

<script>
var nua = navigator.userAgent;
var is_android = ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1));
if(is_android) {
        $('select.form-control').removeClass('form-control').css('width', '100%');

}
</script>



回答3:


something like this might work to recalculate a moment after since the outerHeight of the children was wrong on android at the time (as I mentioned earlier).

window.setTimeout(function() {$(window).trigger('resize');}, 1500);

...might work? Yes that seems to help.

Obviously you just want this to trigger once after the initial loading phase has had time to pass (in obvious error of the spec, which all others are currently complying with).




回答4:


As Matt indicated if you apply any type of border or background to the menu you will vaporize the drop down arrow.

Simplest solution, just remove any border or custom background color. This will leave you with a nice white and gray "modern" looking drop down arrow on Android devices. I don't think there are any sites that it wouldn't fit fine in.




回答5:


If you don’t want to use JavaScript for that and/or just feel bad about UA sniffing (as you should), but are okay with targeting few browsers less:

select
{
    /* common, “safe” styles */
}
@supports (appearance: none)
{
    select
    {
        /* borders and backgrounds */
    }
}

Noticeable absentees are all of IEs (Edge will get full styles): http://caniuse.com/#feat=css-featurequeries



来源:https://stackoverflow.com/questions/14744437/html-select-box-not-showing-drop-down-arrow-on-android-version-4-0-when-set-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!