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

キービジュアル縦横100%表示に関する個人メモ

なにこれ?

ただのメモ。
キービジュアルを画面いっぱいにしたい時のやり方。

どうする

方法は2種類。
①背景画像にして、background-size:cover;
②imgタグで行う場合は、横100%、縦は設定せずに縦横比のままに

①背景画像にして、background-size:cover;

そのうちメモする。

②imgタグで行う場合は、横100%、縦は設定せずに縦横比のままに

keyvisual.php
<div class="common__keyvisual">
  <div class="common__keyvisual--img">
    <img src="画像パス" alt="画像alt">
  </div>
</div>

keyvisual.scss
.common__keyvisual{
  position: relative;
  width: 100%;
  overflow: hidden;
  &--img{
    min-width: 100%;
  }
  img{
    width: 100%;
    height: auto;
  }
}

なんで?

imgタグでbackground-size:cover;みたいな事は出来ない。
object-fit: cover;を使えば出来るけど、
IE非対応なので、弊社では使わず実装しようという流れ。

リンク

参考サイト

background-size - CSS: カスケーディングスタイルシート | MDN

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
No 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
ユーザーは見つかりませんでした