【发布时间】:2021-04-08 20:40:25
【问题描述】:
我试图在我的 Hugo 主页上获得一个网格布局,而不是当前的堆叠版本。这些帖子应该出现在 3 列网格中,而不是一个在另一个之上。首先,我将<article> 标签包裹在list.html 中<div class = "container">:
<div class="container">
<article class="{{ $class }}">
{{- $isHidden := (.Site.Params.cover.hidden | default .Site.Params.cover.hiddenInList)}}
{{- partial "cover.html" (dict "cxt" . "IsHome" true "isHidden" $isHidden) }}
<header class="entry-header">
<h2>
{{ .Title }}
{{- if .Draft }}<div class="entry-isdraft"><sup> [draft]</sup></div>{{- end }}
</h2>
</header>
{{- if (ne .Site.Params.hideSummary true)}}
<section class="entry-content">
<p>{{ .Summary | plainify | htmlUnescape }}...</p>
</section>
{{- end }}
<footer class="entry-footer">
{{- partial "post_meta.html" . -}}
</footer>
<a class="entry-link" aria-label="post link to {{ .Title | plainify }}" href="{{ .Permalink }}"></a>
</article>
{{- end }}
</div>
我查看了主题的 CSS 文件,可以看到帖子的卡片样式为 post-entry。结合起来,我已将此 CSS 添加到 post-entry.css:
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.post-entry {
margin-bottom: var(--gap);
padding: var(--gap);
background: var(--entry);
border-radius: var(--radius);
transition: transform .1s
width: 32%;
padding-bottom: 32%; /* Same as width, sets height */
margin-bottom: 2%; /* (100-32*3)/2 */
position: relative;
}
我认为这是应该的。但这显然行不通。出于某种原因,第一个帖子的宽度减小了,而第二个帖子条目是全宽的。它们并没有像预期的那样并排,但仍然堆叠:See the image here
我的 repo 托管在这里:https://github.com/thedivtagguy/archives,如果这更有帮助的话。
【问题讨论】: