【发布时间】:2020-09-13 03:27:37
【问题描述】:
大家好,需要您对 CSS 布局的指导,
我对 CSS 和 Flexbox 很陌生,并尝试构建一个简单的布局。
我面临的问题是,如何防止pre标签里面的长内容推到别人div
长代码内容前:
经过长代码内容:
从截图来看,有2个问题:
- 左侧边栏和右侧边栏被主内容推送
- 前置内容应该像 StackOverflow 一样包裹成可滚动的
我正在考虑在 pre 标签上设置最大宽度并使用溢出:滚动,但是如何根据父容器设置最大宽度? (父容器是流体)
这是代码笔:
https://codepen.io/cyberflyx/pen/VwaxNWp
<html>
<head>
<title>Learn Max Width</title>
</head>
<body>
<div class="flex justify-between">
<div class="left-sidebar bg-blue p-4">
<h3>This is Left Sidebar</h3>
</div>
<div class="main-content flex-1 bg-yellow p-4">
<div class="content-body">
<h3>Main Content</h3>
<p>This is long content between all of use</p>
<pre>
Sep 10 17:10:30 api-testapp-03 testapp.commands.generate_logs.run_test(): NOTICE: Got events:/home/m/app/testapp/queues/test.queue
</pre>
</div>
</div>
<div class="right-sidebar bg-red p-4">
<h3>This is Right Sidebar</h3>
</div>
</div>
</body>
</html>
CSS
.flex {
display: flex;
}
.justify-between {
justify-content: space-between;
}
.left-sidebar {
}
.content-body {
}
.right-sidebar {
}
pre {
background-color: pink;
padding: 4px;
border-radius: 10px;
/* overflow: scroll; */
/* max-width: 500px; */
}
.flex-1 {
flex: 1 1 0%;
}
.p-4 {
padding: 4px;
}
.bg-blue {
background-color: blue;
}
.bg-yellow {
background-color: yellow;
}
.bg-red {
background-color: red;
}
【问题讨论】: