简体   繁体   English

如果元素具有焦点,如何删除悬停效果?

[英]How do I remove a hover effect if the Element has focus?

I am trying to add hover and focus effects to my input boxes. 我正在尝试将悬停和焦点效果添加到我的输入框中。

On hover the box outline will be GREEN. 悬停时,框的轮廓将为绿色。

On focus the box outline will be BLUE. 焦点框上的轮廓将为蓝色。

Currently I hit a bump where if the input box has focus, it turns BLUE, but if I hover over it, it turns GREEN. 目前,我碰到一个颠簸,如果输入框具有焦点,它将变成蓝色,但是如果将鼠标悬停在它上面,它将变成绿色。

I want to prevent the box from initiating the 'hover' effect if the box has focus. 如果框具有焦点,我想防止框启动“悬停”效果。

CSS: CSS:

input[type=text],
textarea {
  -webkit-transition: all 0.30s ease-in-out;
  -moz-transition: all 0.30s ease-in-out;
  -ms-transition: all 0.30s ease-in-out;
  -o-transition: all 0.30s ease-in-out;
  outline: none;
  padding: 3px 0px 3px 3px;
  margin: 5px 1px 3px 0px;
  border: 1px solid #DDDDDD;
}
input[type=text]:focus,
textarea:focus {
  box-shadow: 0 0 5px rgba(81, 203, 238, 1);
  padding: 3px 0px 3px 3px;
  margin: 5px 1px 3px 0px;
  border: 1px solid rgba(81, 203, 238, 1);
}
input[type=text]:hover,
textarea:hover {
  box-shadow: 0 0 5px rgba(46, 255, 138, 1);
  padding: 3px 0px 3px 3px;
  margin: 5px 1px 3px 0px;
  border: 1px solid rgba(46, 255, 138, 1);
}

How can I prevent the hover effect from executing while the input box has a focus? 如何在输入框处于焦点状态时防止执行悬停效果?

Thanks! 谢谢!

The effects take precedence in the order you place them, so if you put them like this, it should work 效果按放置顺序优先,因此,如果这样放置效果,它应该可以工作

input[type=text],
textarea {
  -webkit-transition: all 0.30s ease-in-out;
  -moz-transition: all 0.30s ease-in-out;
  -ms-transition: all 0.30s ease-in-out;
  -o-transition: all 0.30s ease-in-out;
  outline: none;
  padding: 3px 0px 3px 3px;
  margin: 5px 1px 3px 0px;
  border: 1px solid #DDDDDD;
}

input[type=text]:hover,
textarea:hover {
  box-shadow: 0 0 5px rgba(46, 255, 138, 1);
  padding: 3px 0px 3px 3px;
  margin: 5px 1px 3px 0px;
  border: 1px solid rgba(46, 255, 138, 1);
}
input[type=text]:focus,
textarea:focus {
  box-shadow: 0 0 5px rgba(81, 203, 238, 1);
  padding: 3px 0px 3px 3px;
  margin: 5px 1px 3px 0px;
  border: 1px solid rgba(81, 203, 238, 1);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM