0
0

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

@extendの使い方

Posted at

@extendの使い方

.hoge1 {
margin:10px 0;
padding:5px;
}
.hoge2{
@extend .hoge1;
padding:0;
}

とすることによって、hoge2はhoge1の

margin:10px 0;
padding:5px;

が適応されつつ、そのあとに


padding:0;

が適応されるということになる。

まさに継承、、

mixinと似ているが、mixinは
・グルーピングをしない
・引数を使うことができる
という違いがある
sassでこう記述すると


@mixin hoge($value : 5px) {
margin:20px 0;
padding:$value;
}
.hoge1{
@include hoge;
}
.hoge2{
@include hoge(0);
}

これがcssでは


.hoge1 {
margin: 20px 0;
padding: 5px;
}
.hoge2 {
margin: 20px 0;
padding: 0;
}

こうなる。

引数を指定してあげればスタイル描くの楽そうですね。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?