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

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

我正在尝试为我的输入框添加悬停和焦点效果。

悬停时,框轮廓将为绿色。

聚焦时框轮廓将为蓝色。

目前我碰到了一个问题,如果输入框有焦点,它就会变成蓝色,但如果我将鼠标悬停在它上面,它就会变成绿色。

如果框有焦点,我想阻止框启动 'hover' 效果。

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

如何防止在输入框有焦点时执行悬停效果?

谢谢!

效果按照你放置它们的顺序优先,所以如果你这样放置它们,它应该起作用

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