最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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>

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>
Share Improve this question edited Feb 7, 2013 at 12:16 Mayukh Raaj asked Feb 7, 2013 at 5:44 Mayukh RaajMayukh Raaj 4032 gold badges7 silver badges19 bronze badges 4
  • 1 Have you tried removing the height and/or font-size properties? – Boaz Commented Feb 7, 2013 at 12:22
  • There is an official Android bug about this filled here: code.google.com/p/android/issues/detail?id=48379 – Kozuch Commented Jul 2, 2014 at 16:02
  • It's a little bit late, but I stumbled upon similar thing, I found out that I had a styling of -webkit-appearance:none; I removed that styling and it started showing up again – user1267177 Commented Mar 30, 2016 at 1:21
  • This post is mentioned in Bootstrap official docs getbootstrap.com/docs/4.3/getting-started/browsers-devices – The One Commented Mar 6, 2019 at 21:21
Add a comment  | 

5 Answers 5

Reset to default 18

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;
}

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>

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).

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.

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论