将三个输入框垂直排列(样式3)。

3
我有一个表单,还有一个"+"按钮、文本输入框和"-"按钮,如下图所示。我的问题在于,我无法将其样式设置成所有浏览器上的图片那样。
期望效果: expected style 这是我的页面上它的样子:
Chrome 上看起来像这样:enter image description here 而在 Safari : enter image description here 及在 Explorer : enter image description here 以下是 CSS 代码:

.qty {
  width: 34px;
  height: 20px;
  text-align: center;
  display: block;
}
input.qtyplus {
  padding-top: 4px;
  width: 34px;
  height: 20px;
  border-bottom: 2px solid #ff6100;
  border-left: 2px solid #ff6100;
  border-right: 2px solid #ff6100;
  border-top: 2px black;
  background: black;
  color: #ff6100;
  font-weight: bold;
  border-radius: 0 0 4px 4px
}
input.qtyminus {
  width: 34px;
  height: 20px;
  border-top: 2px solid #ff6100;
  border-left: 2px solid #ff6100;
  border-right: 2px solid #ff6100;
  border-bottom: 2px black;
  background: black;
  color: #ff6100;
  font-weight: bold;
  border-radius: 4px 4px 0 0;
}
input[type=text] {
  background: black;
  color: white;
  font-family: 'Open Sans', sans-serif;
  font-size: 15px;
  font-weight: bold;
  border-left: 2px solid #ff6100;
  border-right: 2px solid #ff6100;
  border-top: 2px black;
  border-bottom: 2px black;
  height: 20px;
  width: 28px;
  margin-top: -1px;
}
<input type='button' value='-' class='qtyminus' field='quantity' />
<input type='text' name='quantity' value='0' class='qty' readonly />
<input type='button' value='+' class='qtyplus' field='quantity' />


1
它不能在哪些浏览器上运行?这将对问题有很大帮助。 - Ruddy
我在FireFox、Chrome和Safari中尝试了一下,它们看起来都很好,我猜测是IE的问题? - Wirde
我在Chrome中发现了一个问题(0比应该小1像素)。 - Stephan Weinhold
大家好,我更新了问题并添加了照片。 - Marcin
1
@Marcin,你的field属性无效吗?你应该使用data-*属性来定义自定义属性。 - Roko C. Buljan
另一种方法是,我建议您使用一个“表格”,在其中添加“输入框”,然后设置表格的边框;)。 - shA.t
2个回答

0

这个有效

.qty {
  background: none repeat scroll 0 0 black;
  border-width: 2px;
  font-weight: bold;
  height: 20px;
  width: 34px;
  cursor: pointer;
}

input.minus {
  border-color: #ff6100 #ff6100 black;
  border-radius: 4px 4px 0 0;
  border-style: solid solid none;
  color: #ff6100;
}

input.plus {
  border-color: black #ff6100 #ff6100;
  border-radius: 0 0 4px 4px;
  border-style: none solid solid;
  color: #ff6100;
  padding-top: 4px;
}

input.num {
  border-color: black #ff6100;
  border-style: none solid;
  color: white;
  display: block;
  font-family: "Open Sans",sans-serif;
  font-size: 15px;
  margin-top: -1px;
  pointer-events: none;
}

文本 => 按钮,类别已更改

<input type='button' value='-' class='qty minus' field='quantity' />
<input type='button' name='quantity' value='0' class='qty num' readonly />
<input type='button' value='+' class='qty plus' field='quantity' />

谢谢。它可以工作,但在我的Chrome页面上有1像素的空间,你知道如何修复吗?图片:http://s4.postimg.org/8khj2r9mh/chr.png - Marcin
是的,如果我能够重现并查看应用的样式,我就可以这样做。但是我在本地看不到那个。我的Chrome版本是42。也许一些其他的样式被继承到您的底部div中。尝试添加 position:relative; top:-1px; 或尝试减少 padding-top - Sithija Darshana

0

这在Firefox、IE和Chrome中似乎对我有效。

这是一个示例fiddle:http://jsfiddle.net/rucaj2cr/10/

HTML

<input type='button' value='-' class='qty qtyminus' field='quantity' />
<input type='text' name='quantity' value='0' class='qty' readonly />
<input type='button' value='+' class='qty qtyplus' field='quantity' />

CSS

.qty {
  height: 20px;
  text-align: center;
  display: block;
  border-left: 2px solid #ff6100;
  border-right: 2px solid #ff6100;
  background: black;
  font-weight: bold;
  padding: 0;
  margin: 0;
}

input.qtyplus {
  border-bottom: 2px solid #ff6100;
  border-top: 2px black;
  color: #ff6100;
  border-radius: 0 0 4px 4px;
  width: 34px;
}

input.qtyminus {
  border-top: 2px solid #ff6100;
  border-bottom: 2px black;
  color: #ff6100;
  border-radius: 4px 4px 0 0;
  width: 34px;
}

input[type=text] {
  color: white;
  font-family: 'Open Sans', sans-serif;
  font-size: 15px;
  border-top: 2px black;
  border-bottom: 2px black;
  margin-top: -1px;
  width: 30px;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接