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

标签 html css ruby-on-rails horizontallistview

我正在尝试水平排列博客文章列表。但我不知道怎么办。我能够在创建静态模型时使用 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/

相关文章:

javascript - JQuery 无法访问下一个目标元素

CSS:100% 高度问题

javascript - ASP.NET MVC 3 HiddenFor Javascript

javascript - 如何使用 AngularJS 保存输入值

html - 多级菜单无响应?

android - 在波斯语 Android 手机中运行应用程序时左右对齐概念发生变化

ruby-on-rails - 事件作业 : Accessible instance variables between callbacks

ruby-on-rails - Active Admin 自定义 400、500 错误页面

ruby-on-rails - 如何在 gem 中扩展 ApplicationController?

html - 你如何通过覆盖它从 Bootstrap 中完全删除样式