html - Firefox 按钮和文本输入错误

标签 html css firefox button input

我有一个非常奇怪的问题,按钮和输入具有相同的 CSS(背景除外),但 Firefox 以不同的方式呈现它们。在 IE 或 Chrome 中没有问题。

#searchInput {
    width: 80%;
    margin: 0 auto;
    display: block;
    height: 40px;
    border: 1px solid #D8D8D8;
    font-size: 1rem;
    padding: 10px;
    text-align: center;
}
#searchButton {
    width: 80%;
    margin: 4px auto;
    display: block;
    height: 40px;
    border: 1px solid #D8D8D8;
    font-size: 1rem;
    padding: 10px;
    text-align: center;
    background: #F2F2F2;
    cursor: pointer;
}

我还包含了容器 CSS,它们都在此处。

.section {
    width: 100%;
    display: inline-block;
    margin: 10px auto;
    background-color: #FAFAFA;
    border-radius: 5px;
    border: 1px solid #D8D8D8;
    padding: 30px;
    position: relative;
}
.toggleIcon {
    width: 28px;
    height: 20px;
    top: 0;
    right: 10px;
    position: absolute;
    border-radius: 5px;
    background: #FAFAFA;
    margin-top: 10px;
    padding: 10px;
    border: 1px solid #D8D8D8;
    cursor: pointer;
    box-sizing: content-box;
}

HTML:

<div id='search' class='section'> <a href="#sidebarNav" class='toggle'><img class = 'toggleIcon' src = 'img/icons/glyphicons_158_show_lines.png' alt = 'Open navigation'></a>
    <img id='logo' src='img/logo.png'>
    <form id='searchForm'>
        <input type='text' id='searchInput' name='searchInput'>
        <button type='submit' id='searchButton' name='searchButton' value='Search'>
            <img src='img/icons/glyphicons_027_search.png' alt='Search'>
        </button>
    </form>
    <div id='searchResults'></div>
</div>

注意!我使用 PageSlide 进行导航,搜索使用 AJAX

最佳答案

根据您最后的评论...

Margin doesn't cause my problems, problem is that input is much wider and higher

您必须将 box-sizing:border-box 属性添加到您的 input#searchInput

喜欢:

#searchInput {
    ....
    box-sizing: border-box;
    -moz-box-sizing: border-box; /* Firefox */
}

工作示例:http://jsfiddle.net/XLyBR/1/

关于html - Firefox 按钮和文本输入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18054612/

相关文章:

css - 可以用CSS制作扇形图吗?

html - 控制 block 元素之间间距的更好方法?

javascript - 火狐扩展。如何捕捉 onload 事件?

javascript - 如何在当前页面显示来自不同页面的按钮元素内的文本?

html - 使文本在响应图像中保持在同一位置

javascript - MouseOut/MouseLeave - 下拉菜单上的事件触发器

firefox - 如何在 Firefox 中设置无衬线字体而不丢失特殊字符

php - 如何使用 OR 和 AND 进行过滤

javascript - 订阅者无法使用 ajax 正常工作

html - 围绕可变高度的 div 画一个完美的圆