html - 如何设置元素样式 :focus without style :hover

标签 html css css-selectors hover focus

请告诉我是否可以使用 style :focus 而不使用 style :hover,即当元素未被选中并且鼠标光标移动到它时,然后应用 style :hover,当元素被选中时并且鼠标光标悬停,样式 :hover is not applied?

例如:

input:focus {
    border: 1px solid red;
}

input:hover {
    border: 1px solid orange;
}

新的可能:

input:focus:not[':hover'] {
    border: 1px solid red;
}

input:hover {
    border: 1px solid orange;
}

最佳答案

您可以使用 :not 选择器轻松完成此操作。这里是关于 :not selector 的详细信息

input:focus:not(:hover) {
    border: 1px solid red;
}
input:hover {
    border: 1px solid orange;
}

关于html - 如何设置元素样式 :focus without style :hover,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47347884/

相关文章:

php - 如何在 stdClass 对象数组 PHP 中使用 array_unique 函数

css - 在 Chrome 和 Safari 中使用 valign=top 的表中 <sup> 的错误呈现

css - 嵌套列表 css 规则支持无限深度

javascript - 在图像上覆盖 div,不知道图像/容器 div 的高度

jquery - 组合多个 css3 选择器

javascript - IE7 中的 jquery 第 n 个选择器

java - 当我当前页面的 html 通过 Jquery 传递到托管 bean 时,primefaces remoteCommand 标记不起作用

javascript - 选择已使用 Jquery 的 .load 加载到页面上的元素

html - 如何删除 <h2> 的 <span> 子级之间的多余空间?

jquery - 传递索引值以用作 jquery 中的选择器