我想在 <input type="text" />
右侧添加一些空间,以便该字段右侧有一些空白空间。
所以,不是 ,而是带有右侧空间的 。
也就是说,相同的行为只是在右侧增加了一些空白空间。
我已经尝试使用 padding-right
,但似乎没有任何效果。
是否有一种方法可以实现这个目标(或者模拟)?
<input type=text id=firstname />
CSS:
input {
width: 250px;
padding: 5px;
}
不过我也会补充一点:
input {
width: 250px;
padding: 5px;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
}
Box sizing使得输入框的宽度保持在250px,而不会因为填充(padding)而增加到260px。
参考链接.
在Windows上,padding-right可以在Firefox/Chrome中正常工作,但在IE中却不行。欢迎来到IE标准不兼容的美妙世界。
请参见:http://jsfiddle.net/SfPju/466/
HTML
<input type="text" class="foo" value="abcdefghijklmnopqrstuvwxyz"/>
CSS
.foo
{
padding-right: 20px;
}
input
标签放在一个 div
中,然后在 div
标签上设置 padding 属性来解决此问题。这对我很有效......<div class="paded">
<input type="text" />
</div>
以及CSS:
.paded{
padding-right: 20px;
}
<div class="FieldElement"><input /></div>
<div class="searchIcon"><input type="submit" /></div>
.FieldElement input {
width: 413px;
border:1px solid #ccc;
padding: 0 2.5em 0 0.5em;
}
.searchIcon
{
background: url(searchicon-image-path) no-repeat;
width: 17px;
height: 17px;
text-indent: -999em;
display: inline-block;
left: 432px;
top: 9px;
}
.FieldElement input {
width: 380px;
border:0;
}
.FieldElement {
border:1px solid #ccc;
width: 455px;
}
.searchIcon
{
background: url(searchicon-image-path) no-repeat;
width: 17px;
height: 17px;
text-indent: -999em;
display: inline-block;
left: 432px;
top: 9px;
}
<input class="form-control search-query input_style" placeholder="Search…" name="" title="Search for:" type="text">
.input_style
{
padding-left:20px;
}
我曾经遇到过类似的问题,通过设置父容器的宽度并添加右侧填充来解决它(以防止填充时改变输入框的大小)。