【发布时间】:2015-07-18 18:34:06
【问题描述】:
我在 Firefox 中遇到这种情况的问题。 #pager 采用其子项的宽度。但是,在 Chrome 中,它采用其父级的宽度。如何让#item-list 在 Firefox 中尊重其父级的宽度?
看看! https://jsfiddle.net/owmpatbh/2/
HTML:
<div id="wrapper">
<div id="sidebar"></div>
<div id="main">
<div id="content">
<p id="stuff">blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah</p>
</div>
<div id="pager">
<div id="item-list">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</div>
</div>
</div>
CSS:
#wrapper {
display: flex;
width: 100%;
height: 100%;
}
#sidebar {
overflow: auto;
flex: 0.25;
border:3px solid green;
min-height: 200px;
}
#main {
display: flex;
flex: .75;
flex-direction: column;
border:3px solid orange;
}
#content {
position: relative;
width: 100%;
flex: 0.85;
border: 3px solid blue;
}
#pager {
display: flex;
position: relative;
width: 100%;
background-color: #fff;
border: 3px solid pink;
flex: 0.15;
}
#item-list {
border: 1px solid black;
width: 100%;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
}
.item {
display: inline-block;
padding: 5px;
width: 200px;
height: 200px;
background-color: red;
}
#stuff {
height: 200px;
}
*{
margin: 3px;
}
【问题讨论】:
-
由于某种原因,它似乎不喜欢固定的 200px 宽度。不知道为什么
-
由于您使用的是 flex,因此您不需要在任何地方使用
width: 100%。取出它不会破坏 Chrome 中的任何内容,也不会使 Firefox 中的任何内容变得更糟。 Firefox 似乎想要#item-list的固定宽度,但同样,我不知道为什么。它似乎不想正确处理 inline-block 子项(或者行为可能尚未明确定义?)