无论表格中有两个输入框,提交按钮都不会对齐
这通常是一个简单的任务。我有一个简单的登录表单,其中包含电子邮件输入、密码输入和提交按钮,全部位于水平线上。经过几个小时的脱掉款式并尝试不同的结构后,按钮的位置比盒子低了一点。我想这可能是因为我已经绝对定位了所涉及的元素,或者它位于具有背景图像的 div 中。
提前致谢。
这是屏幕截图:
这是 html 结构:
<div id="new_home_join">
<div id="sign_up_home">
<div id="sign_in_table">
<form name="sendEmail" action="Home.php" method="post">
<table>
<tr>
<td class="sign_in_input">
<input type="text" name="email" class="text" value="Email<?php if($formError == "true") { echo stripslashes($_POST['name']); } ?>" onclick="clearify(this);" />
</td>
<td class="sign_in_input">
<input type="password" name="password" class="text" value="Password<?php if($formError == "true") { echo stripslashes($_POST['']); } ?>" onfocus="clearify(this);" />
</td>
<td class="sign_submit">
<input type="hidden" name="return" value="<?php echo $_GET['return']; ?>" />
<input type="submit" name="subSignIn" value="Login" />
</td>
</tr>
</table>
</form>
<div class="forget_pw">
<a href="password_forget.php">
Forgot Password?
</a>
</div>
</div>
<div id="not_member">
<a href="http://www.cysticlife.org/signUp.php">
<span style="color:#808080;font-size:18px;">Not a CysticLife member?</span><br /> Join our community today!
</a>
</div>
<div id="browse">
or just browse the
<a href="http://www.cysticlife.org/Blogs_future.php">blogs</a> and <a href="http://www.cysticlife.org/Questions_future.php">questions</a>
</div>
</div>
<div id="fuss">
<a href="http://www.cysticlife.org/what-is-cysticlife.php">What is the CysticLife community?</a>
</div>
</div>
这是相关的 css:
#new_home_join {background:url(images/join_today.png) no-repeat;width:333px; height:200px;margin:0px 0px 0px 0px;}
#sign_up_home {width:343px;}
#sign_in_table {width:338px;margin:0px auto 0px auto;position:relative;}
#sign_in_table {width:338px;margin:0px auto 0px auto;position:relative;}
#sign_in_table table tr td.sign_in_input {padding:40px 0px 5px 10px;}
#sign_in_table table tr td.sign_in_input input {width:105px; border:1px #999999 solid;padding:2px;font-family:Arial,Helvetica,sans-serif; font-size:12px; color:#666666;}
#sign_in_table table tr td.sign_submit input{width:72px; height:34px; background:url(images/search_button.png) no-repeat; font-style:Arial,Helvetica, sans-serif; color:#333333; font-size:11px;padding:5px 0px 10px 0px; border:0;}
.forget_pw {margin:5px 0px 0px 0px;position:absolute; top:62px; right:82px;}
.forget_pw a {padding:10px;font-family:Arial,Helvetica, sans-serif; font-size:10px; color:#626262; text-decoration:none;}
.forget_pw a:hover {color:#F37336;}
#sign_in_table table tr td.sign_submit input{width:72px; height:34px; background:url(images/search_button.png) no-repeat; font-style:Arial,Helvetica, sans-serif; color:#333333; font-size:11px;padding:5px 0px 10px 0px; border:0;}
#join_us {margin:0px auto 40px 60px; font-family:Arial,Helvetica, sans-serif; font-size:12px; color:#F37336; font-weight:bold; text-align:left;padding:0px 50px 80px 0px;float:right}
#join_us a {font-family:Arial,Helvetica, sans-serif; font-size:14px; color:#999999;text-decoration:none;}
#join_us a:hover {color:#F37336;}
#fuss {margin:25px auto 0px auto; font-family:Arial,Helvetica, sans-serif; text-align:center; color:#666666; font-size:12px;}
#fuss a {font-family:Arial,Helvetica, sans-serif; font-size:12px; color:#666666; text-decoration:none;}
#fuss a:hover {color:#FF4701;}
This is ordinarily a simple task. I have a simple sign in form that has an email input,password input, and a submit button, all in a horizontal line. After hours and hours of taking styles off, and trying different structures, the button sits a little lower then the boxes. I am thinking it might be because I have absolutely positioned elements involved or that its' sitting in a div that has a background image.
Thanks in advance.
Here is the screen shot:
Here is the html structure:
<div id="new_home_join">
<div id="sign_up_home">
<div id="sign_in_table">
<form name="sendEmail" action="Home.php" method="post">
<table>
<tr>
<td class="sign_in_input">
<input type="text" name="email" class="text" value="Email<?php if($formError == "true") { echo stripslashes($_POST['name']); } ?>" onclick="clearify(this);" />
</td>
<td class="sign_in_input">
<input type="password" name="password" class="text" value="Password<?php if($formError == "true") { echo stripslashes($_POST['']); } ?>" onfocus="clearify(this);" />
</td>
<td class="sign_submit">
<input type="hidden" name="return" value="<?php echo $_GET['return']; ?>" />
<input type="submit" name="subSignIn" value="Login" />
</td>
</tr>
</table>
</form>
<div class="forget_pw">
<a href="password_forget.php">
Forgot Password?
</a>
</div>
</div>
<div id="not_member">
<a href="http://www.cysticlife.org/signUp.php">
<span style="color:#808080;font-size:18px;">Not a CysticLife member?</span><br /> Join our community today!
</a>
</div>
<div id="browse">
or just browse the
<a href="http://www.cysticlife.org/Blogs_future.php">blogs</a> and <a href="http://www.cysticlife.org/Questions_future.php">questions</a>
</div>
</div>
<div id="fuss">
<a href="http://www.cysticlife.org/what-is-cysticlife.php">What is the CysticLife community?</a>
</div>
</div>
and here is the relevant css:
#new_home_join {background:url(images/join_today.png) no-repeat;width:333px; height:200px;margin:0px 0px 0px 0px;}
#sign_up_home {width:343px;}
#sign_in_table {width:338px;margin:0px auto 0px auto;position:relative;}
#sign_in_table {width:338px;margin:0px auto 0px auto;position:relative;}
#sign_in_table table tr td.sign_in_input {padding:40px 0px 5px 10px;}
#sign_in_table table tr td.sign_in_input input {width:105px; border:1px #999999 solid;padding:2px;font-family:Arial,Helvetica,sans-serif; font-size:12px; color:#666666;}
#sign_in_table table tr td.sign_submit input{width:72px; height:34px; background:url(images/search_button.png) no-repeat; font-style:Arial,Helvetica, sans-serif; color:#333333; font-size:11px;padding:5px 0px 10px 0px; border:0;}
.forget_pw {margin:5px 0px 0px 0px;position:absolute; top:62px; right:82px;}
.forget_pw a {padding:10px;font-family:Arial,Helvetica, sans-serif; font-size:10px; color:#626262; text-decoration:none;}
.forget_pw a:hover {color:#F37336;}
#sign_in_table table tr td.sign_submit input{width:72px; height:34px; background:url(images/search_button.png) no-repeat; font-style:Arial,Helvetica, sans-serif; color:#333333; font-size:11px;padding:5px 0px 10px 0px; border:0;}
#join_us {margin:0px auto 40px 60px; font-family:Arial,Helvetica, sans-serif; font-size:12px; color:#F37336; font-weight:bold; text-align:left;padding:0px 50px 80px 0px;float:right}
#join_us a {font-family:Arial,Helvetica, sans-serif; font-size:14px; color:#999999;text-decoration:none;}
#join_us a:hover {color:#F37336;}
#fuss {margin:25px auto 0px auto; font-family:Arial,Helvetica, sans-serif; text-align:center; color:#666666; font-size:12px;}
#fuss a {font-family:Arial,Helvetica, sans-serif; font-size:12px; color:#666666; text-decoration:none;}
#fuss a:hover {color:#FF4701;}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我注意到一些事情:
1. 你可以简化这个。这些选择器过于复杂,并且会减慢页面渲染和代码读取速度(请参阅编写高效 CSS):
上面的代码将与您的代码执行相同的操作。而且,它不依赖于 HTML 结构。
2. 在查看属性时,我注意到所有表格单元格都有不同的填充:
您应该确保垂直填充相同:
3. 提交按钮具有定义的高度,但输入没有。如果高度高于输入的高度,则需要将其垂直居中对齐:
4. 确保提交按钮图像顶部没有白色/透明条纹。
5. 确保将所有垂直输入边距设置为 0:
6. 尝试将隐藏的输入字段移到提交按钮之后。不应该改变任何东西,但谁知道呢:)
7. 如果上述方法都没有帮助,您也可以使用负边距黑客(但这并不是一个很好的解决方案):
8. 您碰巧有重复的 .sign_submit 输入规则。删除其中之一以避免难以跟踪的错误。
9. 在查看您的 PHP 代码时,我注意到您直接将 $_GET 内容嵌入到页面中。这被认为是危险的,您应该始终使用 htmlentities 对其进行清理以避免 XSS。
编辑:
查看网站后,只需将 .sign_submit 的垂直对齐更改为底部即可修复我的 Opera 浏览器中的问题:
A few things I noticed:
1. You can simplify this. These selectors are overcomplicated and slow down both the rendering of the page and reading the code (see Writing Efficient CSS):
The above will do the same as your code. Moreover, it doesn't depend on the HTML structure.
2. When looking at the properties, I notice that all the table cells have a different padding:
You should make sure the vertical padding is the same:
3. The submit button has a defined height but the inputs do not. If the height is higher than the height of the inputs, it is necessary to vertically align it to middle:
4. Make sure that the submit button image does not have a white/transparent stripe on the top.
5. Make sure you set all vertical input margins to 0:
6. Try to move the hidden input field after the submit button. Should not change anything but who knows :)
7. If none of the above helps, you might also use a negative margin hack (but it's not really a nice solution):
8. You happen to have the rule for .sign_submit input duplicated. Remove one of them to avoid hard to track errors.
9. When looking at your PHP code, I notice you directly embed the $_GET contents to the page. This is considered dangerous and you should always sanitize this using htmlentities to avoid XSS.
EDIT:
After looking at the site, simply changing the vertical-align of .sign_submit to bottom fixes the problem in my Opera browser:
将
vertical-align: Bottom
添加到td.sign_submit
。它当前在 global.css 中设置为baseline
。之后,您可能需要添加一些顶部填充像素才能使定位完全正确。
编辑:
看来您需要为此制定一条新规则:
Add
vertical-align: bottom
totd.sign_submit
. It's currently set tobaseline
in global.css.After that, you may need to add a few pixels of top padding to get the positioning exactly correct, though.
Edit:
Looks like you'll need a new rule for that: