gpt4 book ai didi

html - 将 div 与 rails 生成的循环水平对齐

转载 作者:太空宇宙 更新时间:2023-11-03 21:18:49 24 4
gpt4 key购买 nike

我正在尝试水平排列博客文章列表。但我不知道怎么办。我能够在创建静态模型时使用 css flexbox 实现我想要的结果,但是一旦我用 rails 循环替换占位符标签,布局就会中断并且所有帖子都垂直排列。另外,在上一篇文章的结尾下方,有一串文本,所有帖子信息都 float 在底部(见附图),不确定我在这里做错了什么。 strings at the bottom of the post

下面是我的 html 和 css 设置:

  <section id="posts" class="wrapper">
<h2>My Latest Articles</h2>
<hr>

<div class="post_container">
<div class="article">
<%= @posts.each do |p| %>
<h3 class="post_title"><%= link_to p.title, p %></h3>
<p class="post_date"><%= p.created_at.strftime("%A,%b %d") %></p>
<p class="content"><%= truncate(p.content, length: 400) %></p>
<% end %>
</div>
</div>

CSS

#posts {
padding: 6.5em 0 10em 0;
h2 {
text-align: center;
color: $text;
margin-bottom: 1.25rem;
}

.post_container {
padding: 6em 0 6em 0;
display: flex;
justify-content: space-between;
align-items: flex-start;
.article {
max-width: 28%;
}
.post_title {
color: $text;
font-size: 1.6em;
}
.post_date {
padding: .75rem 0;
color: $accent;
font-size: 1.2em;
}
.content {
color: $grey;
}
}
}

最佳答案

要删除帖子下方的信息字符串,您需要修改您的erb代码。

post_container div 更改为:

<div class="post_container">
<div class="article">
<% @posts.each do |p| %>
<h3 class="post_title"><%= link_to p.title, p %></h3>
<p class="post_date"><%= p.created_at.strftime("%A,%b %d") %></p>
<p class="content"><%= truncate(p.content, length: 400) %></p>
<% end %>
</div>
</div>

关于html - 将 div 与 rails 生成的循环水平对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39402216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com