我有这个输入类型:
input[type=number] {
width:9vw;
height:10vw;
max-width:42px;
max-height:52px;
text-align: center;
-moz-border-radius: 1px;
-webkit-border-radius: 1px;
border-radius:1px;
text-align:center;
border:3px solid black;
display:inline-block;
margin-left:6%;
background-color:black;
color:white;
}
<input type="number" MIN="0" MAX="15" default="2" >
我注意到显示会随着浏览器的不同而变化。我会设置箭头始终可见并覆盖整个高度。我只会黑色背景上的白色箭头。我还需要将默认值设置为 2。感谢您的帮助
最佳答案
正如 durbnpoisn 所说,您可以简单地设置一个 value
属性来解决您的默认值问题。
由于您为输入字段指定了类型,因此您引用的是 HTML5 输入字段,它会自动包含这些箭头。要获得一些自定义箭头,您必须尝试使用 -webkit-appearance: none;
。为此,我找到了 2 个简单的解释来实现此目的 here和 here .
组合在一起看起来像这样:
<input type="number" value="2">
input[type=number] {
width: 9vw;
height: 10vw;
max-width: 42px;
max-height: 52px;
text-align: center;
-moz-border-radius: 1px;
-webkit-border-radius: 1px;
border-radius: 1px;
text-align: center;
border: 3px solid black;
display: inline-block;
margin-left: 6%;
background-color: black;
color: white;
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
/* display: none; <- Crashes Chrome on hover */
-webkit-appearance: none;
margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
background: #eee url('http://i.stack.imgur.com/YYySO.png') no-repeat 50% 50%;
width: 14px;
height: 14px;
padding: 4px;
position: relative;
right: 4px;
border-radius: 28px;
}
您也可以在 fiddle 中查看一下.
关于html - 样式输入类型=数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35273377/