html - 中心提交按钮与表单框一致

标签 html css button alignment

我曾尝试将我的提交按钮与表单的一个条目对齐,但没有成功。我只是希望提交按钮稍微位于表单框的右侧和中心。目前,它位于框的右侧但稍微靠近底部。

我已经尝试了所有不同的响应来回答有关对齐提交按钮( float 、边距等)的类似问题,但我终究找不到正确的选择!

我的 HTML 看起来像这样:

<input name="query" id="querybox" style="width:400px;height:40px;font-size:26px;border-radius:15px;border=0;">
        </input>

    <input type="button" value="Search" id="search" style="width:100px;height=40px;font-size=20px;"/>

设置按钮样式的 CSS 如下所示:

    #search {
cursor:pointer; 
    width:70px; 
    height: 31px; 
    line-height:0; 
    font-size:0; 
    text-indent:-999px;
    color: transparent;  
    background: url(ico-search.png) no-repeat #151B54 center; 
    border: 1px solid #FFFFFF; 
    -moz-border-radius: 2px; 
    -webkit-border-radius: 2px; 
}

#submit:hover {
    background: url(ico-search.png) no-repeat center #151B54; 
    border: 1px solid #FFFFFF;

    }

非常感谢任何帮助!!谢谢。

最佳答案

像这样将每个输入包装在一个 div 中

<div class="vertAlign">
    <input name="query" id="querybox" style="width:400px;height:40px;font-size:26px;border-radius:15px;border=0;"></input>
</div>

<div class="vertAlign"> 
    <input type="button" value="Search" id="search" style="width:100px;height=40px;font-size=20px;"/>
</div>​

然后应用这个css

.vertAlign{
    display: inline-block;
    vertical-align:middle;
}​

这是一个fiddle结果

注意:您所有的 CSS 都应该保持原样。我在我的 fiddle 中省略了它,以便解决方案更具可读性。

关于html - 中心提交按钮与表单框一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12359068/

相关文章:

button - 带自定义字段的 Paypal 按钮

jquery - grails 中带有 2 个按钮的 div

html - 透明边框和框阴影问题

javascript - jQuery 元素大小调整在实时站点上不起作用,在本地版本上起作用。 Chrome

html - 页眉不在页面的最顶部

javascript - 具有 fadeto 功能的网页单选按钮

html - 如何使用 CSS 过渡从导航栏下方滑出子菜单?

javascript - 按下键盘键时的JS功能?

html - 使用 Haml 的 CSS ID 和嵌套标签

html - Css - 理解 "word-wrap: break-word;"