本文翻译自:Can I hide the HTML5 number input’s spin box?

Is there a consistent way across browsers to hide the new spin boxes that some browsers (such as Chrome) render for HTML input of type number? 跨浏览器是否有一致的方法来隐藏某些浏览器(如Chrome)为类型编号的HTML输入呈现的新旋转框? I am looking for a CSS or JavaScript method to prevent the up/down arrows from appearing. 我正在寻找一种CSS或JavaScript方法来防止上/下箭头出现。

<input id="test" type="number">

#1楼

参考:https://stackoom.com/question/FuC7/我可以隐藏HTML-号码输入的旋转框吗


#2楼

Try using input type="tel" instead. 请尝试使用input type="tel" It pops up a keyboard with numbers, and it doesn't show spin boxes. 它弹出一个带数字的键盘,它不显示旋转框。 It requires no JavaScript or CSS or plugins or anything else. 它不需要JavaScript或CSS或插件或其他任何东西。


#3楼

Firefox 29 currently adds support for number elements, so here's a snippet for hiding the spinners in webkit and moz based browsers: Firefox 29目前增加了对数字元素的支持,所以这里有一个片段用于在基于webkit和moz的浏览器中隐藏微调器:

 input[type='number'] { -moz-appearance:textfield; } input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; } 
 <input id="test" type="number"> 

#4楼

To make this work in Safari I found adding !important to the webkit adjustment forces the spin button to be hidden. 为了在Safari中使用,我发现添加!对webkit调整非常重要,强制隐藏旋转按钮。

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {/* display: none; <- Crashes Chrome on hover */-webkit-appearance: none !important;margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
}

I am still having trouble working out a solution for Opera as well. 我仍然无法为Opera制定解决方案。


#5楼

Short answer: 简短回答:

 input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; } input[type="number"] { -moz-appearance: textfield; } 
 <input type="number" /> 

Longer answer: 更长的回答:

To add to existing answer... 要添加到现有答案......

Firefox: 火狐:

In current versions of Firefox, the (user agent) default value of the -moz-appearance property on these elements is number-input . 在当前版本的Firefox中,这些元素上的-moz-appearance属性的(用户代理)默认值是number-input Changing that to the value textfield effectively removes the spinner. 将其更改为值textfield有效地删除微调器。

input[type="number"] {-moz-appearance: textfield;
}

In some cases, you may want the spinner to be hidden initially , and then appear on hover/focus. 在某些情况下,您可能希望最初隐藏微调器,然后显示在悬停/焦点上。 (This is currently the default behavior in Chrome). (这是目前Chrome中的默认行为)。 If so, you can use the following: 如果是这样,您可以使用以下内容:

 input[type="number"] { -moz-appearance: textfield; } input[type="number"]:hover, input[type="number"]:focus { -moz-appearance: number-input; } 
 <input type="number"/> 

Chrome: 铬:

In current versions of Chrome, the (user agent) default value of the -webkit-appearance property on these elements is already textfield . 在当前版本的Chrome中,这些元素上的-webkit-appearance属性的(用户代理)默认值已经是textfield In order to remove the spinner, the -webkit-appearance property's value needs to be changed to none on the ::-webkit-outer-spin-button / ::-webkit-inner-spin-button pseudo classes (it is -webkit-appearance: inner-spin-button by default). 为了删除微调器,需要在::-webkit-outer-spin-button / ::-webkit-inner-spin-button伪类上将-webkit-appearance属性的值更改为none (它是-webkit-appearance: inner-spin-button默认情况下为-webkit-appearance: inner-spin-button )。

 input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; } 
 <input type="number" /> 

It's worth pointing out that margin: 0 is used to remove the margin in older versions of Chrome. 值得指出的是: margin: 0用于删除旧版 Chrome中的保证金。

Currently, as of writing this, here is the default user agent styling on the 'inner-spin-button' pseudo class: 目前,在撰写本文时,这里是'inner-spin-button'伪类的默认用户代理样式:

input::-webkit-inner-spin-button {-webkit-appearance: inner-spin-button;display: inline-block;cursor: default;flex: 0 0 auto;align-self: stretch;-webkit-user-select: none;opacity: 0;pointer-events: none;-webkit-user-modify: read-only;
}

#6楼

I've encountered this problem with a input[type="datetime-local"] , which is similar to this problem. 我在input[type="datetime-local"]遇到了这个问题,这与此问题类似。

And I've found a way to overcome this kind of problems. 我找到了克服这类问题的方法。

First, you must turn on chrome's shadow-root feature by "DevTools -> Settings -> General -> Elements -> Show user agent shadow DOM" 首先,你必须通过“DevTools - >设置 - >常规 - >元素 - >显示用户代理阴影DOM”打开chrome的阴影根功能

Then you can see all shadowed DOM elements , for example, for <input type="number"> , the full element with shadowed DOM is: 然后你可以看到所有阴影的DOM元素 ,例如,对于<input type="number"> ,带有阴影DOM的完整元素是:

 <input type="number"> <div id="text-field-container" pseudo="-webkit-textfield-decoration-container"> <div id="editing-view-port"> <div id="inner-editor"></div> </div> <div pseudo="-webkit-inner-spin-button" id="spin"></div> </div> </input> 

And according to these info, you can draft some CSS to hide unwanted elements, just as @Josh said. 根据这些信息,您可以草拟一些CSS来隐藏不需要的元素,就像@Josh所说的那样。

我可以隐藏HTML5号码输入的旋转框吗?相关推荐

  1. HTML5日期输入类型

    HTML5日期输入类型(date) 在很多页面和web应用中都有输入日期和时间的地方,最典型的是订飞机票,火车票,酒店,批萨等网站. 在HTML5之前,对于这样的页面需求,最常见的方案是用Javasc ...

  2. html自动年份版权,如何将html5日期输入限制在合理的年份

    html5 input type ='date'用于Chrome中以输入最新免费jqgrid中的日期.如何将html5日期输入限制在合理的年份 它允许输入5位数字的日期,如20161. 如何解决此问题 ...

  3. html 星空效果,html5 canvas炫酷旋转银河系星空背景特效

    这是一款html5 canvas炫酷旋转银河系星空背景特效.该特效通过canvas来绘制银河系星盘,并制作星系旋转的效果,非常炫酷. 使用方法 HTML结构 该旋转银河系星空背景特效的HTML结果只需 ...

  4. 供应商主数据和客户主数据各个字段进行显示、必输、隐藏和可选输入的配置学习...

    sap为用户提供了账户组.公司.作业(可以理解为TCODE)三个层面的字段的显示.必输.隐藏和可选输入的配置,他们对应的TCode和路径如下. 客户主数据 按账户组设置屏幕 T-Code: OVT0 ...

  5. html5 语音输入小话筒,HTML5语音输入方法

    谷歌的网站是时逛时新啊,今天在他们首页发现了HTML5的新玩法--语音搜索.可惜的是只有webkit核心的浏览器才能使用.用法很简单 只需要在input添加属性 x-webkit-speech 即可, ...

  6. html5怎么设置勾选,word文档怎么设置输入勾选框

    我们做报告或者调查问卷时候最常用的应该就是勾选框了吧,那么怎么输入呢?下面学习啦小编就为大家介绍一下,一起来看看吧! word文档输入勾选框的方法 输入勾选框步骤1:首先我个人比较喜欢通过某些输入法软 ...

  7. 旋转框检测方法综述:RotateAnchor系列

    ↑ 点击蓝字 关注极市平台 作者丨emiya@知乎 来源丨https://zhuanlan.zhihu.com/p/105881332 极市导读 本文主要介绍了RRPN.R3Det.ROITransf ...

  8. 基于HTML5 Canvas 实现弹出框

    2019独角兽企业重金招聘Python工程师标准>>> 用户鼠标移入时,有弹出框出现,这样的需求很常见.这在处理HTML元素实现时简单,但是如果是对HTML5 Canvas 构成的图 ...

  9. android 弹出弹框2秒消失_基于HTML5 Canvas 实现弹出框

    前言 用户鼠标移入时,有弹出框出现,这样的需求很常见.这在处理 HTML 元素实现时简单,但是如果是对 HTML5 Canvas 构成的图形进行处理,这种方法不再适用,因为 Canvas 使用的是另外 ...

最新文章

  1. 分布式K/V存储方案
  2. 10 个神奇的网站显示超强的 HTML5 技术
  3. unfold3d自动展uv_Maya2018超实用建模及UV展开功能视频教程
  4. LeetCode 851. 喧闹和富有(拓扑排序)
  5. mysql表空间增长过快_Oracle表空间增长异常解决又一例
  6. 深入理解Tomcat系列之五:Context容器和Wrapper容器
  7. html公差符号输入,CAD特殊符号输入:公差符号、直径符号等
  8. android蓝牙取sbc音频数据
  9. MathType求和符号中的黑三角该如何消除
  10. 三角形面积的计算公式,外接圆半径
  11. 【地理】从物理到地理之自然地理提纲整理2——大气圈
  12. 整理了一下oxidized+mysql+gitlab,感觉很好用,做个记录
  13. Selenium.Chrome相关配置及用法
  14. 论文参考文献格式(GB7714-2005)_庄启智_新浪博客
  15. 软件配置项变更与基线变更
  16. Linux配置SAP JCO驱动
  17. Jmeter阶梯式加压的方式
  18. Ts官方文档翻译-Generic范型
  19. 有限差分方法的matlab编程,有限差分方法的MATLAB编程
  20. 5-3 本题要求实现对图的深度优先遍历。 本题中图的表示采用邻接表表示

热门文章

  1. velocity map list 数组操作
  2. UPESB天气查询用例(三)
  3. linux是一个工程而不是理论
  4. GitHub的实现是否是基于此语言的支持网络编程性呢?
  5. 如何才能成为一个高效工作的软件工程师?
  6. 《Android开发从零开始》——17.Service学习(3)
  7. Ubuntu下Linux系统文件恢复
  8. MySQL基于日志还原数据
  9. Ubuntu中rsync配合inotify做服务器间文件同步
  10. 添加Zabbix Agent客户端,并解决报错。