繁体   English   中英

在显示屏上将高度设置为100%:如果'flex'行中的项目过多(仅Firefox),表格将无法工作

[英]Setting height 100% on display:table won't work if a 'flex' row has too many items (only firefox)

我有一张桌子,桌子的高度为100%,有三行,第一行和最后一行具有固定的高度,中间的一行没有特定的高度,因此可以延伸到必要的高度。

问题是,如果您在该行中填充了太多项目,则表将太大,并且将超过100%。

<div id="wrapper">
<div id="first" class="row">
    <div>
    first
    </div>
</div>

<div id="second" class="row">
  <div>


    <div style="height:50px">
    cont0
    </div>
    <div style="height:50px">
    cont1
    </div>
    <div style="height:50px">
    cont2
    </div>
    <div style="height:50px">
    cont3
    </div>
    <div style="height:50px">
    cont4
    </div>
    <div style="height:50px">
    cont5
    </div>
  </div>
</div>
<div id="first" class="row">
     <div>
    last
    </div>
</div>

html, body {height:100%; margin:0; padding:0;}

#wrapper{
   width:300px;
   height:100%;
   display:table;
}
.row 
{
   display:table-row;
}

#first
{
   height:50px;
   margin-bottom:5px;
   background-color:#F5DEB3;    
}

#second{
   background-color:#9ACD32;
}
#second > div{
  height:100%;
  border: 1px solid red;
  overflow-y: auto;
}

这很难解释,但是这个小提琴对此进行了演示: http : //jsfiddle.net/3EjX8/127/

用chrome鼠标调整表的大小,它将表现良好(滚动条出现在表内部)。 但是在firefox中调整它的大小,它将具有这种意外行为。

也许我错了,而我正在承担Chrome的大部分错误。

我只是想知道是否有可能像在chrome上那样使它在firefox中表现出来。

谢谢。

我使它可以同时在Firefox和Chrome上使用。

  1. 不要为此使用display:table
  2. 您的ID为“ first”两次。
  3. 您不需要div内的div
  4. 使用“计算”​​可以节省生命。

http://jsfiddle.net/foreyez/p3rcyofk/

<div id="wrapper">
    <div id="first" class="row">

        first

    </div>

    <div id="second" class="row">
      <div>


        <div style="height:50px">
        cont0
        </div>
        <div style="height:50px">
        cont1
        </div>
        <div style="height:50px">
        cont2
        </div>
        <div style="height:50px">
        cont3
        </div>
        <div style="height:50px">
        cont4
        </div>
        <div style="height:50px">
        cont5
        </div>
      </div>
    </div>
    <div id="last" class="row">

        last

    </div>
</div>


html, body {height:100%; margin:0; padding:0;}
#wrapper
{
   width:300px;
   height:100%;
}


#first,#last
{
   height:50px;
   background-color:#F5DEB3;

}

#second{
   background-color:#9ACD32;
}
#second {
  height:calc(100% - 100px);
  border: 1px solid red;
  overflow-y: auto;
}

在 a 中设置“width: auto”<div> 用“显示:弯曲; flex-direction:行”不起作用</div><div id="text_translate"><p>我正在尝试将一堆 div 并排放置,从左到右。 所以我使用 flexbox 方向设置为row 。</p><p> 我希望这些 div 中的每一个都从里面的内容中导出它们的高度和宽度,因此我将它们的高度和宽度保留为默认值。</p><p> 最后,我想使用 svg 作为背景。 为此,我使用了一个网格容器并将 svg 和 div 放置在同一列和同一行中,如此<a href="https://stackoverflow.com/a/51949049/9613633" rel="nofollow noreferrer">stackoverflow 帖子</a>中所建议的那样。 我将 svg 的高度和宽度设置为100% ,以确保它填充整个背景。</p><p> 但是,当我将所有内容组合在一起时,div 的宽度设置不正确。 div 的高度似乎是由里面的内容设置的,但宽度似乎总是默认为300px 。 对于我的一生,我无法弄清楚这个宽度是如何计算的。 如果内容比300px宽,那么一切都按预期工作。 但是如果内容小于300px ,则容器永远不会缩小以适应。</p><p> 如何确保 div 始终缩小以适应? 请参阅下面的代码示例: </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> .top { padding: 20px; display: flex; flex-direction: row; }.grid-container { background-color: red; display: grid; }.svg { grid-column: 1; grid-row: 1; width: 100%; height: 100%; }.content { grid-column: 1; grid-row: 1; font-size: 100px; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> This div has calculated width 300px for some reason &lt;div class="top"&gt; &lt;div class="grid-container" key="1"&gt; &lt;svg class="svg" viewBox="-10 -10 20 20" preserveAspectRatio="none"&gt; &lt;polygon strokeWidth="0" fill="yellow" points="0,-10 10,0 0,10 -10,0" /&gt; &lt;/svg&gt; &lt;div class="content"&gt; ab &lt;/div&gt; &lt;/div&gt; &lt;,-- more grid-containers --&gt; &lt;/div&gt; This works as expected &lt;div class="top"&gt; &lt;div class="grid-container"&gt; &lt;svg class="svg" viewBox="-10 -10 20 20" preserveAspectRatio="none"&gt; &lt;polygon strokeWidth="0" fill="yellow" points="0,-10 10,0 0,10 -10,0" /&gt; &lt;/svg&gt; &lt;div class="content"&gt; abcdefghijkl &lt;/div&gt; &lt;/div&gt; &lt;!-- more grid-containers --&gt; &lt;/div&gt;</pre></div></div><p></p></div>

[英]Setting “width: auto” inside a <div> with “display: flex; flex-direction: row” doesn't work

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将弹性项目设置为 100% 高度 显示:flex无法在Firefox或Safari浏览器中使用 只有Firefox使用display:table-cell忽略100%的高度 高度:100%; 不会工作 按百分比设置表行高度在Firefox上不起作用。 解决方案? IFRAME在IE8中不会显示100%的高度,但在IE11和Firefox中可以显示 高度为100%时将div设置为高度的100% Flex / CSS Div 不会增长到父身高的 100% 如果容器也具有以百分比表示的最小高度,则以百分比表示的CSS最小高度将不起作用 在 a 中设置“width: auto”<div> 用“显示:弯曲; flex-direction:行”不起作用</div><div id="text_translate"><p>我正在尝试将一堆 div 并排放置,从左到右。 所以我使用 flexbox 方向设置为row 。</p><p> 我希望这些 div 中的每一个都从里面的内容中导出它们的高度和宽度,因此我将它们的高度和宽度保留为默认值。</p><p> 最后,我想使用 svg 作为背景。 为此,我使用了一个网格容器并将 svg 和 div 放置在同一列和同一行中,如此<a href="https://stackoverflow.com/a/51949049/9613633" rel="nofollow noreferrer">stackoverflow 帖子</a>中所建议的那样。 我将 svg 的高度和宽度设置为100% ,以确保它填充整个背景。</p><p> 但是,当我将所有内容组合在一起时,div 的宽度设置不正确。 div 的高度似乎是由里面的内容设置的,但宽度似乎总是默认为300px 。 对于我的一生,我无法弄清楚这个宽度是如何计算的。 如果内容比300px宽,那么一切都按预期工作。 但是如果内容小于300px ,则容器永远不会缩小以适应。</p><p> 如何确保 div 始终缩小以适应? 请参阅下面的代码示例: </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> .top { padding: 20px; display: flex; flex-direction: row; }.grid-container { background-color: red; display: grid; }.svg { grid-column: 1; grid-row: 1; width: 100%; height: 100%; }.content { grid-column: 1; grid-row: 1; font-size: 100px; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> This div has calculated width 300px for some reason &lt;div class="top"&gt; &lt;div class="grid-container" key="1"&gt; &lt;svg class="svg" viewBox="-10 -10 20 20" preserveAspectRatio="none"&gt; &lt;polygon strokeWidth="0" fill="yellow" points="0,-10 10,0 0,10 -10,0" /&gt; &lt;/svg&gt; &lt;div class="content"&gt; ab &lt;/div&gt; &lt;/div&gt; &lt;,-- more grid-containers --&gt; &lt;/div&gt; This works as expected &lt;div class="top"&gt; &lt;div class="grid-container"&gt; &lt;svg class="svg" viewBox="-10 -10 20 20" preserveAspectRatio="none"&gt; &lt;polygon strokeWidth="0" fill="yellow" points="0,-10 10,0 0,10 -10,0" /&gt; &lt;/svg&gt; &lt;div class="content"&gt; abcdefghijkl &lt;/div&gt; &lt;/div&gt; &lt;!-- more grid-containers --&gt; &lt;/div&gt;</pre></div></div><p></p></div>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM