18
21

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 5 years have passed since last update.

アスペクトを保持したまま、background-imageのサイズを変更

Last updated at Posted at 2016-10-21

デモ:http://codepen.io/mo4_9/pen/KgALyV

アスペクトを保持したまま、background-imageのサイズを変更する。

@mixin flex-img($w: 16, $h: 9){
  width: 100%;
  height: 0;
  padding-bottom: ($h/$w) * 100%;
  background-size: contain;
  display: block;
}

.item{
  width: 100%;
  span{
    @include flex-img(320, 180);
    background-image: url(http://placeimg.com/320/180/tech);
  }
}

追記
PostCSSのパッケージpostcss-utilitiesに同じやつあった

18
21
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
18
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?