【发布时间】:2020-02-24 01:37:31
【问题描述】:
我在 flex 列中模拟了一个 flex 表,尽管我很努力,但我不得不放弃 table 对象并只使用 flex 对象。 http://olivier.lahaye1.free.fr/SystemImager/log_table.html
现在我想避免为列设置任意宽度并模仿表格列,这会将自身调整为列中最大的子项。
我想用纯 CSS 来做(我正在使用 HTML5)
我希望第 1 列和第 2 列在不换行的情况下获得最小宽度。
现在我使用的是 8em 的固定宽度,是任意的。
header > :not(:last-child), .row > :not(:last-child), footer > :not(:last-child) {
flex: 0 0 auto;
width: 8em;
text-align: center;
}
header > :last-child, .row > :last-child, footer > :last-child {
flex: 1 1 auto;
padding-left: 1em;
}
<header>
<div>Tag</div>
<div>Priority</div>
<div>Messages (All logs).</div>
</header>
<article id="serverData">
<div class='row'><div>systemimager</div><div>Warning</div><div>Warning message</div></div>
<div class='row'><div>kernel</div><div>info</div><div>Loading driver e1000e.</div></div>
<div class='row'><div>systemimager</div><div>Error</div><div>Imaging of host failed.</div></div>
</article>
有没有办法将 > :first-child 的宽度设置为 header 的所有第一个孩子 + 所有 .row 元素中最大的? (对于 > :nth-child(2) 也一样)
的语法允许类似:
width: max((header > :first-child, .row > :first-child, .footer > :first-child).width); 存在吗?
【问题讨论】:
-
您的代码缺少部分 CSS 来演示您的问题,但这看起来像是典型的网格布局,而不是 flex。
-
提供的链接包含所有代码,包括完整的 css(查看源代码)。网格布局的问题是标题行会滚动。我需要一个静态页眉和一个静态页脚以及可滚动的行。
标签: html css flexbox column-width