2

这通常是一项简单的任务。我有一个简单的登录表单,它有一个电子邮件输入、密码输入和一个提交按钮,所有这些都在一条水平线上。经过数小时脱掉款式并尝试不同的结构后,按钮的位置比盒子低一点。我在想这可能是因为我绝对定位了涉及的元素,或者它位于具有背景图像的 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;}
4

2 回答 2

3

添加vertical-align: bottomtd.sign_submit. 它目前baseline在 global.css 中设置。

之后,您可能需要添加几个像素的顶部填充以使定位完全正确。

编辑:

看起来你需要一个新的规则:

#sign_in_table table tr td.sign_submit { vertical-align: bottom; }
于 2010-09-29T17:00:26.693 回答
2

我注意到的几件事:

#sign_in_table table tr td.sign_in_input { ... }

#sign_in_table table tr td.sign_in_input input { ... }

#sign_in_table table tr td.sign_submit input{ ... }

1. 你可以简化这个。这些选择器过于复杂并且会减慢页面渲染和阅读代码的速度(请参阅编写高效的 CSS):

.sign_in_input  { ... }
.sign_in_input input { ... }
.sign_submit input { ... }

以上将与您的代码相同。此外,它不依赖于 HTML 结构。

2. 查看属性时,我注意到所有表格单元格都有不同的填充:

.sign_in_input {padding:40px 0px 5px 10px;}

.sign_submit { /* No rules, just a default padding */ }

您应该确保垂直填充相同:

.sign_submit { padding-top: 0px; padding-bottom: 0px; }

3.提交按钮有一个定义的高度,但输入没有。如果高度高于输入的高度,则需要将其垂直对齐到中间:

.sign_submit  { line-height: 34px;  /* = Height of the input */ vertical-align: middle; }
.sign_in_input input { height: 30px; /* Better specify the height of the input fields as well*/ /* ... */ }

4. 确保提交按钮图像的顶部没有白色/透明条纹。

5. 确保将所有垂直输入边距设置为 0:

.sign_submit input { margin-top: 0px; margin-bottom: 0px; }

6.尝试移动提交按钮后隐藏的输入字段。不应该改变任何东西,但谁知道:)

7. 如果以上都没有帮助,你也可以使用负边距黑客(但这不是一个很好的解决方案):

.sign_submit input { margin-top: -5px; }

8. 你碰巧有重复的 .sign_submit 输入规则。删除其中一个以避免难以跟踪的错误。

9. 查看您的 PHP 代码时,我注意到您直接将 $_GET 内容嵌入到页面中。这被认为是危险的,您应该始终使用 htmlentities 对其进行清理以避免 XSS。

编辑:

查看该站点后,只需将 .sign_submit 的垂直对齐更改为底部即可解决我的 Opera 浏览器中的问题:

.sign_submit  { vertical-align: bottom; /* Instead of middle */ }
于 2010-09-29T17:04:52.610 回答