在输入文本字段中添加填充以防止重叠

时间:2017-01-27 11:36:35

标签: html css

所以我目前有以下代码:

我遇到的麻烦是我输入的值与百分号重叠。我不知道如何添加一些填充或对齐防止重叠

有什么想法吗?



.percentBlock {
    width: 1500px;
}

.percentageSign {
    position: relative;
    right:20px;
}

<span class="percentBlock">
    <input type="number" max="100" accuracy="2" min="0" style="text-align:right;">
<span class="percentageSign">%</span></span>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:5)

您可以使用以下解决方案,因此%位于数字控件之后:

&#13;
&#13;
.percentBlock {
  width: 1500px;
}
.percentBlock input[type=number] {
  padding-right:20px;
}
.percentageSign {
  position: relative;
  right:20px;
}
&#13;
<span class="percentBlock">
  <input type="number" max="100" accuracy="2" min="0" style="text-align:right;">
  <span class="percentageSign">%</span>
</span>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

看看这个

* {
	box-sizing:border-box;
	-webkit-box-sizing:border-box;
	-ms-box-sizing:border-box;
	-moz-box-sizing:border-box;
}
.percentBlock {
	width: 200px;
	float:left;
	position:relative;
}
.percentageSign {
	position: absolute;
	right: 30px;
    top:1px;
}
.percentBlock input {
	padding-left:70.5%;
	position:relative;
	width:100%;
}
<span class="percentBlock">
	<input type="number" max="100" accuracy="2" min="0">
<span class="percentageSign">%</span></span>

答案 2 :(得分:0)

&#13;
&#13;
.percentBlock {
  width: 1500px;
 }
 .percentBlock input {
  text-align:left;
  width:55px;
 }
 .percentageSign {
	position: relative;
    right:35px;
}
&#13;
<span class="percentBlock">
 <input type="number" max="100" accuracy="2" min="0">
<span class="percentageSign">%</span></span>
&#13;
&#13;
&#13;

我认为这就是你要找的东西。