【发布时间】:2021-04-26 17:59:19
【问题描述】:
我一直在搜索 Stack Overflow 上一个问题的答案,但似乎对我的 Firefox 问题没有帮助。
我的所有输入都是 type="search",然后是一些 CSS 来显示一个清晰的 button,这似乎在 Edge、IE、Chrome 中有效,但在 Firefox 中无效。
input[type="search"]::-webkit-search-cancel-button {
-webkit-appearance: none;
height: 1em;
width: 1em;
border-radius: 50em;
background: url(https://pro.fontawesome.com/releases/v5.10.0/svgs/solid/times-circle.svg) no-repeat 50% 50%;
background-size: contain;
opacity: 0;
pointer-events: none;
cursor: pointer;
}
input[type="search"]:hover::-webkit-search-cancel-button {
opacity: .3;
pointer-events: all;
}
/* Doesn't displays the 'X' when input 'Disabled' */
input[type="search"]:disabled::-webkit-search-cancel-button {
-webkit-appearance: none;
background: none;
cursor: not-allowed;
}
<input class="form-control mand" type="search" />
截图
Chrome/IE/Edge
FF
Chrome 等“x”显示为 onhover 和 onfocus,但从未在 FF 中显示,因为我使用的是 Fontawesome 图像,所以我觉得这很奇怪。
我也尝试过使用
input[type="search"] {
background: transparent
url(https://pro.fontawesome.com/releases/v5.10.0/svgs/solid/times-circle.svg);
background-position: 7px 7px;
background-repeat: no-repeat;
background-position: 2px 3px;
}
但还是什么都没有。我从另一篇帖子here中引用了上述内容。
【问题讨论】:
-
Firefox 应该支持所有
::-webkit-search-…的东西吗,你验证了吗? -
@mplungjan 输入必须包含一个值才能显示。您对我的帖子所做的更新以允许 sn-p 对我有用
-
顾名思义,
-webkit-search-cancel-button不是标准的伪元素,而是 webkit 浏览器引擎的专有特性。通常,您对小部件样式没有如此高度的控制,尤其是。复杂的。