Disable orange outline highlight on focus

2019-01-04 05:17发布

I am coding an app using jQuery, jqTouch and phonegap and have run across a persistent problem which arises when a user submits a form using the Go button on the soft keyboard.

Although it is easy to get the cursor to move to the appropriate form input element by using $('#input_element_id').focus(), the orange outline highlight always returns to the last input element on the form. (The highlight does not show up when the form is submitted using the form submit button.)

What I need is to find a way either to disable the orange highlight completely or else make it move to the same input element as the cursor.

So far, I have tried adding the following to my CSS:

.class_id:focus {
    outline: none;
}

This works in Chrome but not on the emulator or on my phone. I have also tried editing the jqTouch theme.css to read:

ul li input[type="text"] {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0); and
    -webkit-focus-ring-color:  rgba(0, 0, 0, 0);
}

With no effect. I have also tried each of the following additions to the AndroidManifest.xml file:

android:imeOptions="actionNone"
android:imeOptions="actionSend|flagNoEnterAction"
android:imeOptions="actionGo|flagNoEnterAction"

None of which have any effect.

Update: I have done some more troubleshooting with this and to date have found:

  1. The outline property works only on Chrome, not on the Android browser.

  2. The -webkit-tap-highlight-color property does in fact work on the Android browser, though not on Chrome. It disables the highlight on focus as well as on tapping.

  3. The -webkit-focus-ring-color property does not seem to work on either browser.

15条回答
狗以群分
2楼-- · 2019-01-04 05:50

To make sure the tap-highlight-color property overriding works for you, consider these things first:

Not working:
-webkit-user-modify: read-write-plaintext-only;
// It sometimes triggers the native keyboard to popup when clicking the element

.class:active, .class:focus { -webkit-tap-highlight-color: rgba(0,0,0,0); }
// It's not working if defined for states

Working:
.class { -webkit-tap-highlight-color: rgba(0,0,0,0); }

This case works for Android from v2.3 to v4.x even in a PhongeGap application. I tested it on Galaxy Y with Android 2.3.3, on Nexus 4 with Android 4.2.2 and on Galaxy Note 2 with Android 4.1.2. So don't define it for states only for the element itself.

查看更多
贼婆χ
3楼-- · 2019-01-04 05:52

Use the below code in CSS file

  * {
     -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    }
    :focus {
        outline: 0;
        border:none;
        color: rgba(0, 0, 0, 0);
    }

It's work for me. I hope it work for you.

查看更多
ら.Afraid
4楼-- · 2019-01-04 05:52

If the design doesn't use outlines, this should do the job:

*, *::active, *::focus {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0)!important;
    -webkit-focus-ring-color: rgba(0, 0, 0, 0)!important;
    outline: none!important;
}
查看更多
forever°为你锁心
5楼-- · 2019-01-04 06:01

This didn't work for me on Image Map Area links, the only working solution was to use javascript by capturing the ontouchend event and preventing default browser behavior by returning false on the handler.

with jQuery:

$("map area").on("touchend", function() {
   return false;
});
查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-01-04 06:01

I have tried this one and worked fine :-

HTML:-

<a class="html5logo"  href="javascript:void(0);"  ontouchstart="return true;"></a>

css

.html5logo {
  display: block;
  width: 128px;
  height: 128px;
  background: url(/img/html5-badge-128.png) no-repeat;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
  -webkit-tap-highlight-color: transparent; /* For some Androids */
}
.html5logo:active {
  -webkit-transform: scale3d(0.9, 0.9, 1);
}
查看更多
狗以群分
7楼-- · 2019-01-04 06:02

Try:

-webkit-tap-highlight-color: rgba(255, 255, 255, 0); 
-webkit-tap-highlight-color: transparent;  // i.e. Nexus5/Chrome and Kindle Fire HD 7''
查看更多
登录 后发表回答