如果使用像素填充,我的表单输入将正确显示,但使用左右百分比填充会将其中断.我无法弄清楚为什么.
它适用于Safari,在Firefox 3.5.3 OSX中已经破解.
问题是,当我使用百分比填充时,填充都会中断(因此输入值不能很好地对齐的原因.)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>% padding</title>
<style>
html,body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td {
margin:0;
padding:0;
border:none;
}
div.content {
width:50%;
margin:0 auto;
background:#eee;
}
div.content form {
width:100%;
}
div.content form ul {
list-style:none;
margin:0;
width:100%;
}
div.content form li {
position:relative;
margin-bottom:20px;
height:64px;
width:100%; /* width is declared */
}
div.content form li label {
position:absolute;
width:auto;
left:0;
top:0;
line-height:20px;
}
div.content form li .text {
position:absolute;
bottom:0;
left:0;
padding:10px 2%; /* if 2% is changed to 2px the padding works correctly */
width:96%;
font-size:14px;
outline:1px solid #ccc;
}
</style>
</head>
<body>
<div class="content">
<form action="" method="get">
<ul>
<li>
<label for="text">Input</label>
<input type="text" class="text" name="text" value="" />
</li>
<li>
<label for="text">Input</label>
<input type="text" class="text" name="text" value="" />
</li>
<li>
<label for="text">Input</label>
<input type="text" class="text" name="text" value="" />
</li>
</ul>
</form>
</div>
</body>
</form>
Run Code Online (Sandbox Code Playgroud)
这里有一个开放的(在撰写本文时)错误:
https://bugzilla.mozilla.org/show_bug.cgi?id=527459
更新: 错误终于得到修复!2012-11-18 15:35太平洋标准时间
它适用于 IE 和 Chrome。只有火狐似乎不适合我。
我知道在 Firefox 中解决这个问题的唯一方法是这样的(只需将文本框包装在带有正确填充的 div 内)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>% padding</title>
<style>
html,body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td {
margin:0;
padding:0;
border:none;
}
div.content {
width:50%;
margin:0 auto;
background:#eee;
}
div.content form {
width:100%;
}
div.content form ul {
list-style:none;
margin:0;
width:100%;
}
div.content form li {
position:relative;
margin-bottom:20px;
height:64px;
width:100%; /* width is declared */
}
div.content form li label {
position:absolute;
width:auto;
left:0;
top:0;
line-height:20px;
}
div.content form li .text {
position:absolute;
bottom:0;
left:0;
padding:10px 2%; /* if 2% is changed to 2px the padding works correctly */
width:96%;
font-size:14px;
outline:1px solid #ccc;
}
div.content form li .textbox {
position:absolute;
bottom:0;
left:0;
padding:10px 2%; /* if 2% is changed to 2px the padding works correctly */
width:96%;
font-size:14px;
outline:1px solid #ccc;
border:1px solid #ccc;
background-color:white;
}
.textbox {
width:100%;
border:solid 1px white;
}
</style>
</head>
<body>
<div class="content">
<form action="" method="get">
<ul>
<li>
<label for="text">Input</label>
<div class='text'>
<input type="text" class="textbox" name="text" value="" />
</div>
</li>
<li>
<label for="text">Input</label>
<div class='text'>
<input type="text" class="textbox" name="text" value="" />
</div>
</li>
<li>
<label for="text">Input</label>
<div class='text'>
<input type="text" class="textbox" name="text" value="" />
</div>
</li>
</ul>
</form>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)