html - 设置输入文本和输入提交在同一高度的问题

标签 html css input vertical-alignment

我想将文本输入放在与提交按钮相同的行和高度上。查看JSFiddle .在 Chrome 中这是完美的,但在 Firefox 中提交按钮低于文本输入。我该如何解决。 HTML

<div id="whois-lookup">
    <form id="whois-form">
        <input type="text" placeholder="search" id="name-check" />
        <input type="submit" name="query" />
    </form>
</div>

还有CSS

#whois-lookup input[type=text]
    {
        margin: 0;
        border: 1px solid #aaa;
        border-right: 0px;
        font-size: 1.0em;
        line-height: 25px;
        height: 25px;
        padding: 0 10px;
        width: 188px;
        border-top-left-radius: 3px;
        border-bottom-left-radius: 3px;
        position: relative;
        top: -2px;
    }

    #whois-lookup input[type=text]:focus
    {
        outline: none;
    }

    #whois-lookup input[type=submit]
    {
        margin-left: -4px;
        border: 1px solid #aaa;
        border-left: 0px;
        font-size: 1.0em;
        line-height: 27px;
        height: 27px;
        border-top-right-radius: 3px;
        border-bottom-right-radius: 3px;
        color: #666;
        cursor: pointer;
        background-color: #fff;
    }

最佳答案

如前所述(请参阅 CBroe 的评论),您只需要以下 CSS,请参阅嵌入式评论:

#whois-lookup
{
    top: 0;   /** Don't need top/right, no effect for static positioning **/
    right: 0;
}


#whois-lookup input[type=text]
{
    margin: 0;
    border: 1px solid #aaa;
    border-right: 0px;
    font-size: 1.0em;
    line-height: 25px;
    height: 25px;
    padding: 0 10px;
    width: 188px;
    border-top-left-radius: 3px;
    border-bottom-left-radius: 3px;
    position: relative; /** Not needed relative/top **/
    top: -2px; 
    vertical-align: bottom; /** top will also work... **/
}

#whois-lookup input[type=text]:focus
{
    outline: none;
}

#whois-lookup input[type=submit]
{
    margin-left: -4px;
    border: 1px solid #aaa;
    border-left: 0px;
    font-size: 1.0em;
    line-height: 27px;
    height: 27px;
    border-top-right-radius: 3px;
    border-bottom-right-radius: 3px;
    color: #666;
    cursor: pointer;
    background-color: #fff;
    vertical-align: bottom; /** top will also work... **/
}

您为输入文本和输入提交元素设置了两个不同的行高和高度,不是很明显但似乎有效。

fiddle :http://jsfiddle.net/audetwebdesign/WVG9L/17/

关于html - 设置输入文本和输入提交在同一高度的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16238441/

相关文章:

javascript - 适用于较小屏幕的汉堡菜单,包括 JavaScript/jQuery

javascript - AngularJS 在指令运行之前通过 AJAX 检索数据

java - Spring 表单输入不能被禁用

javascript - HTML - 数字输入限制(向上/向下 10 到 10)

javascript - jQuery 动画有效但不适用于 Safari

python - 如何自动在 Python 函数中设置 "input"?

html - 确定子元素是否被父元素剪切的纯 CSS 方法?

javascript - 如何动态添加另一个选项卡到引导选项卡

html - 堆叠一些图像

c# - 如何修复具有某些分组行的 GridView 中的荧光笔?