LoginSignup
0
1

More than 3 years have passed since last update.

要素の横並び HTML/CSS

Posted at

はじめに

要素を横並びにしたいのです

sample.html
<div class="contents">
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
</div>
sample.css
.item{
  width: 100px;
  height: 100px;
  background-color: black;
  margin:30px;
}

今のままだと・・・2e71b5df5f4186b9630a1b91598e1af0.png

こんな時は・・・
親要素にdisplay: flex;をかけちゃいます。

sample.css
.contents{
  display: flex;
}

10a1b6f0c620dbe0d18b49cf35359cc3.png
やりました!!!:point_up::point_up:

最後に

display: flex;という名前の響きが大好きです。

0
1
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
0
1