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,
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>
<button class="btn btn-primary num-badge num-badge--text-primary" data-num-badge="9">Primary button</button>
<button class="btn btn-primary num-badge num-badge--text-primary num-badge--border-primary" data-num-badge="9">Primary button</button>
<button class="btn btn-primary num-badge num-badge--text-primary num-badge--border-primary num-badge--font-awesome" data-num-badge="&#xf021;">Primary button</button>
<a class="num-badge" data-num-badge="9">Basic Link</a>;</pre>
</article>
<aside>
aside right
</aside>
</main>
<footer>
footer
</footer>
答案 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;
}
此处更详细地解释了问题和解决方案: