Help us understand the problem. What is going on with this article?

imageを2列で並び、真ん中にする方法

More than 3 years have passed since last update.

やりたいこと

画像を2列に並ぶ
画像の高さは縦横の比率で自動調整
画像のリンクはパーツのどこでも押せること

サンプルコード

https://jsfiddle.net/yangchuntao/ovzxo2v4/

説明

css
display: flex;
flex-wrap: wrap;

flexを使って、改行を入れる

css
&__column_2 {
  width: 46%;
  margin: 5px 2%;
}

2列なので、margin-left margin-rightを2%にして、widthを46%にする

css
&__link {
  display: table;
  min-height: 100px;
  height: 100%;
}

画像は高さは可変なので、画像の高さと合わせる、画像の高さが100px以下の場合は、100pxにして押しやすくする

css
&__image_container {
  display: table-cell;
  vertical-align: middle;
}

画像を真ん中にする

css
&__image {
  width: 100%;
  height: auto;
  max-height: 150px;
}

画像の幅はdivの幅と同じにして、高さは自動調整

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away