使用 CSS HTML 垂直对齐提交按钮
我无法让提交按钮与我在 Internet Explorer 中的输入保持一致。在 safari 和 Firefox 中对齐效果很好,但 IE 使按钮下降了大约 5 像素。有什么想法为什么会发生这种情况或者我该如何解决它?
网址为 http://www.menslifestyles.com 单击页面顶部的“订阅”,将弹出表格。 两个输入笔直排列,但在 ie 中,提交按钮未对齐!
-------html--------
<div id="subscribe">
<form id="subscribeform" method="post" action="/maillists/subscribe" accept-charset="utf-8">
<div style="display:none;"><input type="hidden" name="_method" value="POST"></div>
<label for="MaillistName">Name</label><input name="data[Maillist][name]" type="text" maxlength="255" id="MaillistName">
<label for="MaillistEmail">Email</label><input name="data[Maillist][email]" type="text" maxlength="500" id="MaillistEmail">
<input type="submit" value="Submit"><a href="#" id="closelink">X</a>
</form></div>
-----css--------
#subscribe{
width:620px;
position:absolute;
top:25px;
left:50%;
margin-left:-120px;
overflow: auto;
z-index: 1000;
background: #ffffff;
color:#6e6e6e;
font-size: 10px;
text-transform: uppercase;
font-family: Helvetica, Verdana;
}
#subscribe input{
border: 1px solid #e5e5e5;
display: inline;
height: 12px;
color:#cccccc;
width: 215px;
}
#subscribe input[type="button"], #subscribe input[type="submit"]{
clear:both;
padding:3px, 0px;
-webkit-appearance: none;
font-family: Helvetica, Verdana;
background-color:#cccccc;
text-align:center;
color: #3c3c3c;
font-size:10px;
text-transform: uppercase;
border: none;
cursor: pointer;
display: inline;
height:15px;
width:60px;
position:relative;
margin-left:5px;
}
#subscribe form{
margin:0px;
padding:0px;
}
#subscribe label{
display: inline;
font-size: 10px;
}
#subscribe a{
text-decoration: none;
color: #cccccc;
}
#subscribe #closelink{
padding:0 5px;
}
I am having trouble getting my submit button to display in line with my inputs in internet explorer. The alignment is fine in safari and firefox but IE is dropping the button down about 5px. Any ideas why this is happening or how i can fix it?
The url is http://www.menslifestyles.com
click subscribe at the top of the page the form will pop in.
The two inputs line up straight but in ie the submit button doesn't align!
-------html-------
<div id="subscribe">
<form id="subscribeform" method="post" action="/maillists/subscribe" accept-charset="utf-8">
<div style="display:none;"><input type="hidden" name="_method" value="POST"></div>
<label for="MaillistName">Name</label><input name="data[Maillist][name]" type="text" maxlength="255" id="MaillistName">
<label for="MaillistEmail">Email</label><input name="data[Maillist][email]" type="text" maxlength="500" id="MaillistEmail">
<input type="submit" value="Submit"><a href="#" id="closelink">X</a>
</form></div>
-----css-------
#subscribe{
width:620px;
position:absolute;
top:25px;
left:50%;
margin-left:-120px;
overflow: auto;
z-index: 1000;
background: #ffffff;
color:#6e6e6e;
font-size: 10px;
text-transform: uppercase;
font-family: Helvetica, Verdana;
}
#subscribe input{
border: 1px solid #e5e5e5;
display: inline;
height: 12px;
color:#cccccc;
width: 215px;
}
#subscribe input[type="button"], #subscribe input[type="submit"]{
clear:both;
padding:3px, 0px;
-webkit-appearance: none;
font-family: Helvetica, Verdana;
background-color:#cccccc;
text-align:center;
color: #3c3c3c;
font-size:10px;
text-transform: uppercase;
border: none;
cursor: pointer;
display: inline;
height:15px;
width:60px;
position:relative;
margin-left:5px;
}
#subscribe form{
margin:0px;
padding:0px;
}
#subscribe label{
display: inline;
font-size: 10px;
}
#subscribe a{
text-decoration: none;
color: #cccccc;
}
#subscribe #closelink{
padding:0 5px;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在
#subscribe input[type="button"]、#subscribe input[type="submit"]
的 css 中尝试添加vertical-align: top;
In your css for
#subscribe input[type="button"], #subscribe input[type="submit"]
try to addvertical-align: top;
您应该明确设置填充和边距,某些浏览器具有不同的默认值,这会使事情变得混乱。所以margin-left:5px;变为边距:0 0 0 3px;
表单通常也不一致,您可能想尝试绝对定位提交按钮,在这种情况下给出#subscribe位置:相对,提交按钮位置:绝对;右:0px;顶部:0px;
将来,您可以绕过默认浏览器值,并通过在样式表中设置默认值来获得更一致的外观,请参阅 此处获取您可以包含的重置样式表。 (如果你现在包含这个,它可能会抛出一些东西)
You should set padding and margin explicitly, some browsers have different defaults which will mess things up. So margin-left:5px; becomes margin: 0 0 0 3px;
Forms are also just inconsistent generally, you may want to try and absolutely positioning the submit button, in which case give #subscribe position:relative, and the submit button position:absolute; right:0px; top:0px;
In the future you can get around default browser values, and get a more consistent look by setting default values in your stylesheet , see here for a reset stylesheet that you can include. (If you include this now it might throw a few things out)
在此 css 规则中
#subscribe input[type="button"], #subscribe input[type="submit"]
更改
将
position:relative
为
position:absolute 应该可以解决问题
。在 IE 8 中测试并有效。
In this css rule
#subscribe input[type="button"], #subscribe input[type="submit"]
Change
position:relative
to
position:absolute
Should do the trick. Tested in IE 8 and works.
提交按钮在不同的浏览器中似乎有不同的默认边距和填充值。
我认为这必须在某些 重置样式表 中这并不是唯一令人烦恼的跨浏览器“默认”值差异。网络什么时候能够标准化,这是另一个话题。
我们是这样做的:
我注意到 IE8、Firefox 和 GChrome 之间存在非常小的差异,但其他浏览器中可能也存在差异。
这里的表单将其位置设置为“相对”,以便当我将按钮的位置设置为绝对时,按钮本身的位置相对于 searchForm。
Submit button seem to have different default margin and padding values in different browsers.
I assume this must be in some reset Stylesheet as this is not the only annoying cross browser "default" values discrepancy. When is the web going to standardize this is another subject.
This is how we do it:
I noticed very small discrepancies between IE8, Firefox and GChrome but there may be in other browsers.
The form here has its position set to "relative" so that when I set the button's position to absolute, the button position itself relatively to the searchForm.