Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

html - CSS - How to stop input being highlighted when tapped on mobile

Solution: Webkit Tap Highlight Color

I have an input field that is a textbox. When a user taps it on mobile, it briefly flashes a black shadow around the box like in the picture related.

The following GIF image is a screen recording of the bar being tapped on a mobile device. How do I stop the black shadow from flashing around the box for a split second when it is tapped?

Textbox gif

enter image description here

.searchBar {
  height: 46px;
  border-radius: 2px;
  background-color: #fff;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  box-shadow: 0 2px 2px 0 rgb(0 0 0 / 20%), 0 0 0 1px rgb(0 0 0 / 13%);
}

.searchBox {
  flex: 1;
  border: none;
  background-color: transparent;
  padding: 17px;
  font-size: 16px;
  color: #000;
  outline: none !important;
  box-shadow: none !important;
  -moz-appearance: none;
  -webkit-appearance: none;
}

.searchButton {
  border: none;
  background-color: transparent;
  height: 46px;
  width: 46px;
  padding-right: 17px;
  justify-content: center;
  outline: none !important;
  cursor: pointer;
  display: inline;
}
<div class="searchBar">

  <input class="searchBox">

  <button class="searchButton" type="submit" value="Search"><i class="fas fa-search"></i> </button>

</div>
question from:https://stackoverflow.com/questions/66056498/css-how-to-stop-input-being-highlighted-when-tapped-on-mobile

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I couldn't see any shadow flashes in the output of your code.But this may help i used this to remove the blue tap color that appears while clicking on button. Just add this

*{      
-webkit-tap-highlight-color: transparent;
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...