Skip to content

Instantly share code, notes, and snippets.

@shirokuro331
Created December 6, 2012 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shirokuro331/4224692 to your computer and use it in GitHub Desktop.
Save shirokuro331/4224692 to your computer and use it in GitHub Desktop.
Sprite について(dimention編)

続・Sprite について

一つ前の Gist でSprite について触れたが、あれだけだと単に画像をひとまとめにして、それぞれのセレクタを作ってくれるだけ。

width や height の値も入るようにしよう。

@import "my-icons/*.png";
@include all-my-icons-sprites($dimensions:true);

上記のように ($dimentions:true) と付け足すだけで

.my-icons-sprite,
.my-icons-tongue, 
.my-icons-wink {
  background: url('/images/my-icons-saa905fd6f5.png') no-repeat;
}

.my-icons-tongue {
  background-position: 0 -64px;
  height: 64px;
  width: 64px;
}

.my-icons-wink {
  background-position: 0 0;
  height: 64px;
  width: 64px;
}

のように height と width の値も自動的に入力してくれる。
あとは html 側で

<div class="my-icons-tongue"></div>
<div class="my-icons-wink"></div>

と記述するだけで画像が表示されるようになる。
でも、ほかにもやり方あるみたいなので他の方法も探る。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment