Firefox 尺寸渲染对比其他浏览器
Firefox size rendering vs other 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中看到的:
Firefox 显示的内容(Firefox 37):
问题是什么?为什么 Firefox(或我的 Firefox)显示不同的结果?
您的#search-div 太窄,使元素挤在一起。您的搜索 div 也有问题。我建议按搜索选项、搜索框、搜索按钮的顺序排列它们,然后添加 float: left;他们的每个样式以及一些 margin-left: 20px;所以他们不是挨着的。
您的搜索框也有一个小宽度截断字母。
查看这个 jsfiddle:http://jsfiddle.net/3qzb7q0d/1/
类似于:
#search-options {
display: inline-block;
float: left;
margin-left: 20px;
// whatever else
}
将其添加到每个搜索部分。
增加#search-button 的宽度
去掉#search-div
的宽度
输入元素根据浏览器呈现,OS 具有不同的外观。一旦将 type
更改为 search
,Chrome 似乎将 box-sizing: border-box;
应用于输入元素,但 Firefox 不会这样做(目前我会说 Firefox 是没错,但我需要在规格中检查一下)。
Firefox 不会更改这些元素的 box-sizing
,因为默认的 box-sizing
是 content-box
,完整的 outer-width 是width
+ padding
+ border
(更多细节你可以看这里CSS-Tricks: Box Sizing)。从那时起,您在 Firefox 中的 #search-box
没有 outer-width 325px
。
如果您想更好地控制元素的外部宽度,您需要为box-sizing
使用border-box
。您可以使用 :
更改整个页面的 box-sizing
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
来自站点的代码:Paul Irish: * { Box-sizing: Border-box } FTW
使用 border-box
.
更新了 jsfiddle
请看这个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中看到的:
Firefox 显示的内容(Firefox 37):
问题是什么?为什么 Firefox(或我的 Firefox)显示不同的结果?
您的#search-div 太窄,使元素挤在一起。您的搜索 div 也有问题。我建议按搜索选项、搜索框、搜索按钮的顺序排列它们,然后添加 float: left;他们的每个样式以及一些 margin-left: 20px;所以他们不是挨着的。
您的搜索框也有一个小宽度截断字母。
查看这个 jsfiddle:http://jsfiddle.net/3qzb7q0d/1/
类似于:
#search-options {
display: inline-block;
float: left;
margin-left: 20px;
// whatever else
}
将其添加到每个搜索部分。
增加#search-button 的宽度
去掉#search-div
的宽度输入元素根据浏览器呈现,OS 具有不同的外观。一旦将 type
更改为 search
,Chrome 似乎将 box-sizing: border-box;
应用于输入元素,但 Firefox 不会这样做(目前我会说 Firefox 是没错,但我需要在规格中检查一下)。
Firefox 不会更改这些元素的 box-sizing
,因为默认的 box-sizing
是 content-box
,完整的 outer-width 是width
+ padding
+ border
(更多细节你可以看这里CSS-Tricks: Box Sizing)。从那时起,您在 Firefox 中的 #search-box
没有 outer-width 325px
。
如果您想更好地控制元素的外部宽度,您需要为box-sizing
使用border-box
。您可以使用 :
box-sizing
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
来自站点的代码:Paul Irish: * { Box-sizing: Border-box } FTW
使用 border-box
.