包含<pre> content not shrinking

时间:2018-03-13 15:09:22

标签: html css html5 css3 flexbox

I have a layout where I need to hold <aside> with fixed width and middle content as fluid. Everything is fine but if you used <pre> element inside middle content and you will try to resize window to small resolution after that is <pre> without horizontal scroll and flex element is overflowed. <pre> element is as block element, with overflow: auto.

Any ideas how to resolve it?

Thanks a lot, best regards,

jsFiddle

body {
  margin: 0;
}

header {
  background-color: green;
}

footer {
  background-color: red;
}

header,
footer {
  width: 100%;
  height: 100px;
}

main {
  display: flex;
  background-color: purple;
}

aside {
  overflow-x: hidden;
  flex: 0 0 270px;
}

article {
  flex-grow: 1;
  min-height: 100vh;
  background-color: lightgray;
}

pre {
  overflow: auto;
  font-size: 87.5%;
  color: #dc3545;
}
<header>
  header
</header>
<main>
  <aside>
    aside left
  </aside>
  <article>
    <h1>CONTENT</h1>
    <pre>
&lt;button class=&quot;btn btn-primary num-badge num-badge--text-primary&quot; data-num-badge=&quot;9&quot;&gt;Primary button&lt;/button&gt;
&lt;button class=&quot;btn btn-primary num-badge num-badge--text-primary num-badge--border-primary&quot; data-num-badge=&quot;9&quot;&gt;Primary button&lt;/button&gt;
&lt;button class=&quot;btn btn-primary num-badge num-badge--text-primary num-badge--border-primary num-badge--font-awesome&quot; data-num-badge=&quot;&amp;#xf021;&quot;&gt;Primary button&lt;/button&gt;
&lt;a class=&quot;num-badge&quot; data-num-badge=&quot;9&quot;&gt;Basic Link&lt;/a&gt;;</pre>
  </article>
  <aside>
    aside right
  </aside>
</main>
<footer>
  footer
</footer>

1 个答案:

答案 0 :(得分:1)

overflow: auto元素上有pre

pre {
  overflow: auto;
  font-size: 87.5%;
  color: #dc3545;
}

它不能自行溢出。它溢出了父母。

因此,请将overflow移至article

article {
  overflow: auto; /* new */
  flex-grow: 1;
  min-height: 100vh;
  background-color: lightgray;
}

revised jsfiddle

此处更详细地解释了问题和解决方案: