html - 样式输入类型=数字

标签 html css

我有这个输入类型:

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 个简单的解释来实现此目的 herehere .

组合在一起看起来像这样:

<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/

相关文章:

javascript - 变量上的 Jquery 选择器

javascript - 单击菜单项以在主干 View 中突出显示

html - 网络浏览器开发

css - 使用 HTML5 元素与自定义元素的优势

html - 具有相同 ID 的多个元素响应一个 CSS ID 选择器

javascript - 在 HTML 表单中实现下拉选项菜单的正确方法是什么?

javascript - Rails 通讯录

html - 单个 UL CSS 中的三个 LI 列

html - `margin:auto;` 不适用于行内 block 元素

android - 安卓全屏背景图片