1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

display: flex; アウトプット

Last updated at Posted at 2021-03-24

display: flex;は、親要素に記述し、
子要素のclassセレクタ内に横並びにする内容を記述します。

.card__wrapper {
  display: flex;  /*親要素に記述*/
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
}

.card { /*子要素*/
  width: calc((100% - 50px) / 3);
  margin-bottom: 40px;
}

↓each文の外に親要素のclassセレクタを記述します。


  <div class="card__wrapper"> #親要素
    <% @tweets.each do |tweet| %>
          <%= render partial: "tweets/tweet", locals: { tweet: tweet } %>
    <% end %>
  </div>

↓render先のファイルです。
 子要素でまとめることで、子要素ごとにeach文で繰り返しされます。

<div class="card"> #子要素
  <%= link_to '詳細', tweet_path(tweet.id), class: :card__btn, method: :get %>
  <%= link_to '編集', edit_tweet_path(tweet.id), class: :card__btn, method: :get %>
  <%= link_to '削除', tweet_path(tweet.id), class: :card__btn, method: :delete %>
  <%= link_to "投稿者: #{tweet.user.nickname}", user_path(tweet.user.id), class: :card__user, method: :get %>    
  <%= "タイトル: #{tweet.title}" %>  
  <%= "内容: #{tweet.text}" %><br>
</div>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?