使用 CSS HTML 垂直对齐提交按钮

发布于 2024-11-09 01:40:32 字数 2078 浏览 0 评论 0原文

我无法让提交按钮与我在 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">&nbsp;    &nbsp;
<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

泪冰清 2024-11-16 01:40:32

#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 add vertical-align: top;

放飞的风筝 2024-11-16 01:40:32

您应该明确设置填充和边距,某些浏览器具有不同的默认值,这会使事情变得混乱。所以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)

柳絮泡泡 2024-11-16 01:40:32

在此 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.

脸赞 2024-11-16 01:40:32

提交按钮在不同的浏览器中似乎有不同的默认边距和填充值。

我认为这必须在某些 重置样式表 中这并不是唯一令人烦恼的跨浏览器“默认”值差异。网络什么时候能够标准化,这是另一个话题。

我们是这样做的:

#searchForm {
    position: relative;   // you must keep this
    font-weight: normal;
    font-family: Arial, Helvetica, sans-serif;
    margin-bottom: 30px;
}
input#searchBtn{
    padding: 0;    // you must keep this
    margin: 0;     // you must keep this
    position: absolute;    // you must keep this
    left: 203px;  // you can change this
    top: 2px;
    height: 24px;
    width: 42px;   // you can change this
    font-size: 14px;
    background: url(http://yourDomain/img/yourPrettySearchIcon.png) buttonface no-repeat 9px 1px;
}


<form id="searchForm" name="mySearchForm" action="myPage.html" method="post">
    <input name="searchBtn" value="" id="searchBtn" type="submit"/>
</form>

我注意到 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:

#searchForm {
    position: relative;   // you must keep this
    font-weight: normal;
    font-family: Arial, Helvetica, sans-serif;
    margin-bottom: 30px;
}
input#searchBtn{
    padding: 0;    // you must keep this
    margin: 0;     // you must keep this
    position: absolute;    // you must keep this
    left: 203px;  // you can change this
    top: 2px;
    height: 24px;
    width: 42px;   // you can change this
    font-size: 14px;
    background: url(http://yourDomain/img/yourPrettySearchIcon.png) buttonface no-repeat 9px 1px;
}


<form id="searchForm" name="mySearchForm" action="myPage.html" method="post">
    <input name="searchBtn" value="" id="searchBtn" type="submit"/>
</form>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文