【发布时间】:2015-05-07 22:35:24
【问题描述】:
在我的基于 flexbox 的布局中,我可能有一个 <pre><code></code></pre> 元素(以及其他元素)。因为它的内容可能比容器宽,所以我把它设为overflow-x:auto。
在 Chrome 上完美运行:
但它在 Firefox 上坏了:
如果没有硬编码的尺寸,我该如何解决这个问题?
div,pre {
padding: 5px;
color: white;
}
.m {
background: #222;
display: flex;
}
.l, .r {
background: #143;
flex: 0 0 100px;
}
.c {
background: #971;
flex: 1;
}
pre {
white-space: pre;
word-wrap: normal;
overflow-x: auto;
}
<div class=m>
<div class=l>this must be 100px wide</div>
<div class=c>this must take the remaining space</div>
<div class=r>this must be 100px wide</div>
</div>
<div class=m>
<div class=l>this must be 100px wide</div>
<div class=c>
<pre><code>The following line of code is long:
This is the long line of code the previous line of code was referring to (no, it can't be 72 col, sorry for the inconvenience)</code></pre>
Some other content in the c column.</div>
<div class=r>this must be 100px wide</div>
</div>
【问题讨论】:
-
不确定为什么 Chrome 和 Firefox 的行为不同,但如果可以将
overflow-x: auto; overflow-y: hidden;应用于中间列(具有.c类),则可以解决此问题。 -
@HashemQolami 这不是我想要的(中间列可能包含其他元素)。但这可能有助于为 Firefox 制定解决方法。
-
这真的很奇怪,如果你看到这里:jsfiddle.net/roj0a54k/1
<code>元素是一个内联元素。如果你将它设置为阻止并设置一个奇怪的max-width像 10px 它似乎在 Firefox 中工作。