html - Firefox 尺寸渲染对比其他浏览器

标签 html css google-chrome firefox browser

请看这个jsfiddle

HTML:

<body>
<header>
    <div id="top-header">
        <div id="search-div">
            <form method="get" name="search">
                <input value="Search" id="search-button" type="submit">

                <input name="term" id="search-box" type="search">

                <div id="search-options">
                    <ul>
                        <li id="search-option-icon">0</li>
                        <li>1</li>
                        <li>2</li>
                        <li>3</li>
                        <li>4</li>
                        <li>5</li>
                    </ul>
                    <input name="search-type" id="search-type" type="hidden">
                </div>
            </form>
        </div>
    </div>
    <div id="bottom-header">something here</div>
</header>
</body>

CSS:

*{
    margin:0;
    padding:0;
    font-size:100%;
   border:0 none;
}

body{
    direction: rtl;
}

header{
    position:relative;
    width:100%;
    height: 80px;
}


/*
--------------------------------------------------------
|   header
--------------------------------------------------------
*/
header > div{
    width: 100%;
    position:relative;
    position: relative;
}

#top-header{
    background: #9600ee;
    height: 52px;
}

#bottom-header{
    background: white;
    height: 29px;
    border-bottom: 1px solid #d5d5d5;
    box-shadow:0 1px 1px #e0e0e0;
}

#img-logo{
    display: inline-block;
}

/*
--------------------------------------------------------
|   header > search-div
--------------------------------------------------------
*/
#search-div{
    width:432px;
    position: absolute;
    top:8px;
    height: 36px;
    left:0;
    right:0;
    margin:auto;
    z-index: 3;
}

#search-options{
    height: 36px;
    width: 49px;
    background: #FFFFFF;
    background: linear-gradient(#FFFFFF,#e6e6e6);
    text-align: center;
    display: inline-block;
    vertical-align: middle;
    cursor: pointer;
    left:0;
}

#search-options > ul > li{
    display: none;
}

#search-option-icon{
    display: block !important;
}

#search-options:hover > ul > li{
    width: 49px;
    background: red;
    display: block;
}

#search-box{
    display: inline-block;
    height: 36px;
    width: 325px;
    right:49px;
    padding:0 5px;
    border-right:1px solid #9600ee;
    border-left: 1px solid #d1d1d1;
}

#search-button{
    height: 100%;
    width: 48px;
    background: #FFFFFF;
    background: linear-gradient(#FFFFFF,#e6e6e6);
    border-radius: 0 2px 2px 0;
}

我要创建一个页面,它的方向是从右到左。我不知道为什么 Firefox 显示的结果与其他浏览器不同?

我在 Chrome 中看到的内容: enter image description here

Firefox 显示的内容(Firefox 37): enter image description here

问题是什么?为什么 Firefox(或我的 Firefox)显示不同的结果?

最佳答案

输入元素的呈现取决于具有不同外观的浏览器和操作系统。只要您将 type 更改为 search,Chrome 似乎就会将 box-sizing: border-box; 应用于输入元素,但 Firefox 不会' 这样做(目前我会说 Firefox 是正确的,但我需要在规范中检查这一点)。

Firefox 不会更改这些元素的 box-sizing,因为默认的 box-sizingcontent-box,完整的 < em>outer-width 是 width + padding + border (更多细节你可以看这里 CSS-Tricks: Box Sizing )。从那时起,您在 Firefox 中的 #search-box 没有 325pxouter-width

如果您想更好地控制元素的外部宽度,您需要使用border-box 进行box-sizing .您可以使用以下方法更改整个页面的 box-sizing:

html {
  box-sizing: border-box;
}

*, *:before, *:after {
   box-sizing: inherit;
}

网站代码:Paul Irish: * { Box-sizing: Border-box } FTW

已更新 jsfiddle 使用 border-box

关于html - Firefox 尺寸渲染对比其他浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29046156/

相关文章:

python - Selenium Grid2 - 是否可以运行 10 个 Chrome 实例?

php - 具有大小属性​​的选择框是否适用于 $_POST?

javascript - jQuery MagicSuggest 禁用选择

html - CSS - Span divs 页面的整个高度

javascript - 使用 HTML5、CSS、Node.js、Chromium 嵌入式浏览器的 LOB 桌面应用程序

html - IE9 和 chrome 中的 HTML5 title tooltip 是否有字符长度限制

html - 在浏览器中查看扩展名为 .asp 的本地 html 文件

javascript - Vue.js 组件父事件

javascript - 在我的 slider 图像顶部有不需要的空间

javascript - 对 javascript HTML DOM 遍历感到困惑