如何删除所有默认的 Webkit 搜索字段样式?
默认情况下, 呈现为 Mac OS X 上的“本机”搜索字段(圆角、清除按钮等)。我想完全删除此自定义样式,以便输入看起来与等效文本输入相同 (
),但同时将输入类型设置为
搜索
。
我尝试过 -webkit-appearance: none;
,它非常接近......但是边距/填充发生了一些有趣的事情,我似乎无法覆盖,这导致了宽度搜索字段的渲染比文本输入短约 20px。
是否还有另一个我不知道的 -webkit-
特定属性可以完全禁用样式?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试这些样式:
来源:http://css-tricks.com/ webkit-html5-search-inputs/#comment-82432
Try these stylings:
Source: http://css-tricks.com/webkit-html5-search-inputs/#comment-82432
对于那些仍然需要支持 IE 的用户,值得一提的是,您需要一套完全不同的供应商样式来从 Internet Explorer 中删除“×”
。 blog.maximerouiller.com/post/remove-the-x-from-internet-explorer-and-chrome-input-type-search/" rel="noreferrer">从 Internet Explorer 和 Chrome 输入类型搜索中删除 X:
演示在堆栈片段和jsFiddle
For those that still need to support IE, it's worth mentioning that you need an entirely different set of vendor styles to remove the '×' from Internet Explorer
Per the article Remove the X from Internet Explorer and Chrome input type search:
Demo in Stack Snippets & jsFiddle
到 2023 年,这可以得到简化。
Firefox 搜索字段显示为文本字段。
只有 Chrome 和 Safari 会更改搜索字段的外观。
来源:https://github.com/necolas/normalize.css/blob/8.0.1/normalize.css#L285-L293)
-2px
“打破" Chrome :-/-webkit-search-results-button
和-webkit-search-results-decoration
不需要,因为 Chrome >= 53(发布于2016) 不再支持results
属性。Chrome 117 影子 DOM 仅使用一个伪元素
-webkit-search-cancel-button
特定于input type="search"
:另外 Safari 17.0 Shadow DOM 使用
-webkit-search-decoration< /code> 在 macOS 13.6 下添加左侧内边距,在 iOS 17.0 下在左侧添加放大镜:
演示:
As of 2023, this can be simplified.
Firefox search field appears as a text field.
Only Chrome and Safari change the search field appearance.
(source: https://github.com/necolas/normalize.css/blob/8.0.1/normalize.css#L285-L293)
The
-2px
"breaks" Chrome :-/-webkit-search-results-button
and-webkit-search-results-decoration
are not needed because Chrome >= 53 (released in 2016) does not support theresults
attribute anymore.Chrome 117 shadow DOM uses only one pseudo-element
-webkit-search-cancel-button
which is specific toinput type="search"
:In addition Safari 17.0 shadow DOM uses
-webkit-search-decoration
which adds a left inner padding under macOS 13.6 or a magnifying glass on the left under iOS 17.0:Demo: