forms - 表单标签/输入对齐在 IE7 中不符合预期

标签 forms html css internet-explorer-7

我有一个 html5 表单,它在 IE8 及更高版本中按预期显示,也在 Chrome、Safari、Forefox 和 Opera 中显示。但在 IE7 中,标签对齐方式完全不同 - 标签显示在输入字段上方而不是左侧,并且水平对齐,这正是我所追求的。

我没有在 StackOverflow 上找到这个问题,但确实在 CSS 技巧上找到了一些非常相似的问题。我确实在这里有一个链接,但作为第一次发布者,我的问题被拒绝了,因为其中有超过 2 个链接(由于下面的额外 2 个链接显示了问题的屏幕截图)。所以我不得不删除它......关于 CSS 技巧的帖子的答案给了我一些要看的地方,但它并不具体 - 它说“我自己想出来了。解决方案涉及移动标签标签和一些 IE 条件 CSS。”

这些屏幕截图显示了表单显示的差异:

IE7: http://www.s203574650.websitehome.co.uk/Screenshots/IE7_form.jpg

IE10: http://www.s203574650.websitehome.co.uk/Screenshots/IE10_form.jpg

HTML代码:

<form id="contact" action="contact_us.php" method="post">
<div>
<label for="fullname">Your Full Name:</label>
<input id="fullname" name="fullname" type="text" placeholder="eg. John Smith" required aria-       required="true" >
</div>
<div>
<label for="email">Your Email Address:</label>
<input id="email" name="email" type="email" placeholder="eg. johnsmith@gmail.com" required aria-    required="true" title="Please enter a valid email address">
</div>
<div>
<label for="phone">Your Phone Number (optional):</label>
<input id="phone" name="phone" type="tel" placeholder="eg. 07000 123456" pattern="([0-9]|( |-)?)    {10,14}" title="Please use only digits, spaces and hyphens.">
</div>
<div>
<label for="experience">Your Badminton Experience:</label>
<select name="experience">
<option value="default">Please Choose</option>
                <option value="Intermediate">Intermediate</option>
                  <option value="Advanced">Advanced</option>
                   <option value="Don't know">Don't know</option>
                   </select>                
</div>
 <div>
<label for="club_matches">Have you previously played matches for a club?:</label>
 <input type="radio" name="club_matches" value="Yes">Yes
 <input type="radio" name="club_matches" value="No" checked>No
 </div>
<div>                   
<label for="info">Additional Info / Questions: </label>
<textarea name="info" type="text">
</textarea>
</div>
<div>
<label for="blank"></label>
<input type="submit" id="submit" value="Submit Form" name="sent">
</div>
</form>

还有 CSS:

   /* styles for contact form */
#contact
{
background-color: #DDE2E2;
-webkit-border-radius: 10px;
-o-border-radius: 10px;
-moz-border-radius: 10px; 
border-radius: 10px;
border: solid slategrey 2px;
box-shadow: 3px 3px 5px slategrey;
-o-box-shadow: 3px 3px 5px slategrey;
-moz-box-shadow: 3px 3px 5px slategrey;
-webkit-box-shadow: 3px 3px 5px slategrey;
padding: 3%;
font-family: arial;
color: #0099FF;
font-weight:bold;
align:center;
width: 80%;
margin-left:40px;
}

label
{
width: 40%;
float:left;
text-align:right;
margin-right: 2em;
font-size: 0.8em;
}

label, select, textarea, input
{
margin-bottom: 1.5em;
clear:left;
margin-left: 1em;
}

#submit
{
margin-top: 5%;
margin-bottom: 0;
}

最佳答案

问题是您正在为选择框、文本区域和输入以及标签清除 float ,而您应该只为标签清除它们。

label, select, textarea, input {
    margin-bottom: 1.5em;
    clear: left;
    margin-left: 1em;
}

label, select, textarea, input 的 CSS 选择器中移除 clear: left; 并将其添加到 label 的选择器中:

label {
    width: 40%;
    float: left;
    clear: left;
    text-align: right;
    margin-right: 2em;
    font-size: 0.8em;
}
label, select, textarea, input {
    margin-bottom: 1.5em;
    margin-left: 1em;
}

关于forms - 表单标签/输入对齐在 IE7 中不符合预期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13804750/

相关文章:

javascript - 为什么FormData报错

html - 为什么我的父元素将最后一个字换行? (内部 float 元素)

html - Bootstrap Carousel 中的文本对齐

html - 在 HTML5 中将图例置于底部

php - ZF2 表单的 CSRF 即使使用无效值也会进行验证

forms - Symfony2 : How to modify a form value before validation

javascript - 如何在页面加载时使用 ajax 提交隐藏表单?

javascript - 使用 JS/g 函数替换字符显示未定义

PHP 数据库输出没有显示正确的方式

html - 如何使 &lt;input&gt; 标签多行?