Sassのincludeとは?基礎からマスターしよう
includeがSassにもたらす強力な再利用性
Sassの@includeディレクティブは、定義済みのミックスイン(@mixin)を呼び出すための機能です。これにより、CSSのコードの再利用性が大幅に向上し、保守性の高いスタイリングが可能になります。
// 基本的なmixinの定義
@mixin button-base {
padding: 10px 20px;
border-radius: 4px;
font-weight: bold;
cursor: pointer;
}
// mixinの使用
.primary-button {
@include button-base; // 定義したmixinを呼び出し
background-color: #007bff;
color: white;
}
.secondary-button {
@include button-base; // 同じmixinを別の要素でも使用
background-color: #6c757d;
color: white;
}
mixinとincludeの関係性を理解する
@mixinと@includeは、常にペアで使用される機能です:
- 引数を受け取るmixin
// 引数を受け取るmixinの定義
@mixin flex-container($direction: row, $justify: center, $align: center) {
display: flex;
flex-direction: $direction;
justify-content: $justify;
align-items: $align;
}
// 引数ありのmixinの使用
.card-container {
@include flex-container(column, flex-start, center);
}
// デフォルト値を使用した場合
.centered-content {
@include flex-container; // row, center, centerが適用される
}
- コンテンツブロックを受け取るmixin
// コンテンツを受け取るmixinの定義
@mixin media-query($width) {
@media screen and (max-width: $width) {
@content; // includeで渡されたスタイルがここに展開される
}
}
// コンテンツブロックの渡し方
.responsive-element {
@include media-query(768px) {
font-size: 14px;
padding: 10px;
}
}
- 複数の引数を持つmixin
// 複数の引数を受け取るmixin
@mixin box-shadow($x, $y, $blur, $color) {
-webkit-box-shadow: $x $y $blur $color;
-moz-box-shadow: $x $y $blur $color;
box-shadow: $x $y $blur $color;
}
// キーワード引数を使用した呼び出し
.shadowed-box {
@include box-shadow(
$x: 2px,
$y: 2px,
$blur: 5px,
$color: rgba(0, 0, 0, 0.2)
);
}
mixinとincludeの関係性を理解する上で重要なポイント:
| 機能 | 役割 | 使用タイミング |
|---|---|---|
| @mixin | スタイルの定義 | 再利用可能なスタイルパターンの作成時 |
| @include | mixinの呼び出し | 定義したmixinを実際に適用する時 |
この組み合わせにより、以下のような利点が得られます:
- コードの重複を削減
- メンテナンス性の向上
- スタイルの一貫性確保
- 柔軟なカスタマイズ性
初心者がmixinとincludeを使い始める際は、まずシンプルなスタイルパターンから始めることをお勧めします。使い方に慣れてきたら、徐々に複雑な機能を取り入れていくことで、効率的にSassの恩恵を受けることができます。
Sassのincludeを使いこなすための環境構築
Ruby on Railsプロジェクトでの設定方法
Rails 6以降では、Webpackerを使用したアセットパイプラインがデフォルトとなっていますが、Sassの設定は比較的シンプルです。以下に、具体的な手順を示します。
- 必要なgemの追加
# Gemfile gem 'sass-rails', '~> 6.0' # Rails 6以降用
- アプリケーション構成の設定
# config/application.rb
module YourApp
class Application < Rails::Application
# Sassのプリコンパイル設定
config.sass.preferred_syntax = :scss
config.sass.line_comments = false
config.sass.cache = true
end
end
- ディレクトリ構造の整理
app/ ├── assets/ │ └── stylesheets/ │ ├── application.scss # メインのSassファイル │ ├── mixins/ # mixinを格納するディレクトリ │ │ ├── _buttons.scss │ │ ├── _grid.scss │ │ └── _typography.scss │ └── components/ # コンポーネント別のスタイル │ ├── _header.scss │ └── _footer.scss
アセットパイプラインとの連携のポイント
- アセットの読み込み設定
// app/assets/stylesheets/application.scss // 基本的なmixinの読み込み @import "mixins/buttons"; @import "mixins/grid"; @import "mixins/typography"; // コンポーネントの読み込み @import "components/header"; @import "components/footer";
- 開発環境での最適化設定
# config/environments/development.rb Rails.application.configure do # ソースマップの有効化 config.sass.source_map = true # 開発時のデバッグ情報 config.sass.debug_info = true end
- プロダクション環境での最適化設定
# config/environments/production.rb Rails.application.configure do # 圧縮の有効化 config.assets.css_compressor = :sass # キャッシュの活用 config.sass.cache = true end
設定時の重要なポイント:
| 設定項目 | 推奨設定 | 目的 |
|---|---|---|
| preferred_syntax | :scss | より一般的なCSS構文に近い記法を使用 |
| line_comments | false(本番環境) | コンパイル後のCSSファイルサイズを削減 |
| source_map | true(開発環境) | デバッグを容易にする |
| cache | true | コンパイル速度の向上 |
注意点と推奨事項:
- アセットの整理
- mixinは機能ごとにファイルを分割
- ファイル名の先頭にアンダースコアを付ける(部分ファイルの表記)
- 論理的なディレクトリ構造を維持
- パフォーマンスの考慮
- 必要なmixinのみをインポート
- 開発環境とプロダクション環境で適切な設定を使い分け
- 大規模なmixinは必要に応じて分割
- バージョン管理
- gemのバージョンを明示的に指定
- 環境依存の問題を避けるため、.sass-cacheをgitignoreに追加
これらの設定を適切に行うことで、効率的なSass開発環境を構築できます。特に、チーム開発では一貫した環境を維持することが重要です。
実践で使える7つの活用テクニック
レスポンシブデザインのブレークポイント管理
レスポンシブデザインを効率的に管理するためのmixinとincludeの活用方法です。
// ブレークポイントのマップ定義
$breakpoints: (
'sm': 576px,
'md': 768px,
'lg': 992px,
'xl': 1200px
);
// メディアクエリmixin
@mixin respond-to($breakpoint) {
@if map-has-key($breakpoints, $breakpoint) {
@media screen and (min-width: map-get($breakpoints, $breakpoint)) {
@content;
}
} @else {
@warn "不明なブレークポイントです: #{$breakpoint}";
}
}
// 使用例
.responsive-container {
width: 100%;
padding: 15px;
@include respond-to('md') {
width: 750px;
margin: 0 auto;
}
@include respond-to('lg') {
width: 970px;
}
}
共通のボタンスタイルの実装
再利用可能なボタンスタイルを効率的に管理します。
// ボタンの基本スタイルmixin
@mixin button-base {
display: inline-block;
padding: 0.5em 1em;
border-radius: 4px;
font-weight: 600;
text-align: center;
transition: all 0.3s ease;
cursor: pointer;
}
// ボタンのバリエーションmixin
@mixin button-variant($bg-color, $text-color: white) {
background-color: $bg-color;
color: $text-color;
&:hover {
background-color: darken($bg-color, 10%);
}
&:active {
transform: translateY(1px);
}
}
// 使用例
.btn-primary {
@include button-base;
@include button-variant(#007bff);
}
.btn-success {
@include button-base;
@include button-variant(#28a745);
}
グリッドシステムの構築
カスタマイズ可能なグリッドシステムを実装します。
// グリッド設定
$grid-columns: 12;
$grid-gutter: 30px;
// カラムmixin
@mixin make-col($size) {
flex: 0 0 percentage($size / $grid-columns);
max-width: percentage($size / $grid-columns);
padding-right: $grid-gutter / 2;
padding-left: $grid-gutter / 2;
}
// rowのmixin
@mixin make-row {
display: flex;
flex-wrap: wrap;
margin-right: -($grid-gutter / 2);
margin-left: -($grid-gutter / 2);
}
// 使用例
.row {
@include make-row;
}
.col-6 {
@include make-col(6);
}
.col-4 {
@include make-col(4);
}
アニメーション効果の再利用
汎用的なアニメーション効果を定義し、再利用します。
// フェードインアニメーションmixin
@mixin fade-in($duration: 0.3s, $delay: 0s) {
opacity: 0;
animation: fadeIn $duration ease forwards;
animation-delay: $delay;
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
}
// スライドインアニメーションmixin
@mixin slide-in($direction: 'left', $distance: 30px, $duration: 0.3s) {
opacity: 0;
@if $direction == 'left' {
transform: translateX(-$distance);
} @else if $direction == 'right' {
transform: translateX($distance);
}
animation: slideIn $duration ease forwards;
@keyframes slideIn {
to {
opacity: 1;
transform: translateX(0);
}
}
}
// 使用例
.fade-element {
@include fade-in(0.5s, 0.2s);
}
.slide-element {
@include slide-in('left', 50px, 0.6s);
}
フォーム要素のスタイリング
一貫性のあるフォームスタイルを実装します。
// 入力フィールドの基本スタイルmixin
@mixin input-base {
width: 100%;
padding: 0.5em 0.75em;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 1rem;
line-height: 1.5;
transition: border-color 0.2s ease;
&:focus {
outline: none;
border-color: #007bff;
box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}
}
// フォームグループmixin
@mixin form-group {
margin-bottom: 1rem;
label {
display: block;
margin-bottom: 0.5em;
font-weight: 500;
}
}
// 使用例
.form-group {
@include form-group;
input[type="text"],
input[type="email"] {
@include input-base;
}
}
メディアの効率的な管理
画像やメディア要素のレスポンシブな管理を行います。
// アスペクト比を保持するmixin
@mixin aspect-ratio($width, $height) {
position: relative;
&::before {
content: "";
display: block;
padding-top: percentage($height / $width);
}
> * {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
}
// レスポンシブな画像コンテナmixin
@mixin responsive-image-container {
width: 100%;
overflow: hidden;
img {
max-width: 100%;
height: auto;
display: block;
}
}
// 使用例
.video-container {
@include aspect-ratio(16, 9);
}
.image-gallery {
@include responsive-image-container;
}
ベンダープレフィックス自動付与
クロスブラウザ対応のためのベンダープレフィックス管理を自動化します。
// フレックスボックスmixin
@mixin flexbox {
display: -webkit-box;
display: -webkit-flex;
display: -moz-flex;
display: -ms-flexbox;
display: flex;
}
// トランスフォームmixin
@mixin transform($property) {
-webkit-transform: $property;
-moz-transform: $property;
-ms-transform: $property;
transform: $property;
}
// トランジションmixin
@mixin transition($properties...) {
-webkit-transition: $properties;
-moz-transition: $properties;
-ms-transition: $properties;
transition: $properties;
}
// 使用例
.flex-container {
@include flexbox;
@include transform(translateY(-10px));
@include transition(all 0.3s ease);
}
各テクニックの使用における注意点:
| テクニック | メリット | 注意点 |
|---|---|---|
| レスポンシブデザイン | 一貫性のある breakpoint 管理 | breakpoint の数を必要最小限に |
| ボタンスタイル | 統一されたUIの維持 | カラーバリエーションの管理 |
| グリッドシステム | レイアウトの柔軟な制御 | ネストしすぎない |
| アニメーション | 再利用可能な動的効果 | パフォーマンスへの配慮 |
| フォーム要素 | 一貫したユーザー体験 | アクセシビリティの考慮 |
| メディア管理 | 効率的なメディア表示 | 画像の最適化 |
| ベンダープレフィックス | クロスブラウザ対応 | 必要なプレフィックスの選定 |
これらのテクニックを組み合わせることで、保守性が高く、効率的なスタイリングが可能になります。
使用する際の注意点とベストプラクティスを含める
パフォーマンスへの影響を最小限に抑える方法
includeの過剰な使用はCSSファイルのサイズを肥大化させる可能性があります。以下に、パフォーマンスを最適化するためのベストプラクティスを示します。
- mixinの最適化
// 良い例:必要な機能のみを含むシンプルなmixin
@mixin button($bg-color) {
background-color: $bg-color;
color: white;
padding: 10px 20px;
}
// 悪い例:過剰に機能を詰め込んだmixin
@mixin button-complex($bg-color, $size, $radius, $shadow, $animation...) {
// 多すぎるパラメータと機能は保守性を低下させる
background-color: $bg-color;
font-size: $size;
border-radius: $radius;
box-shadow: $shadow;
transition: $animation;
// ... 多数のプロパティ
}
- コードの重複を防ぐ
// 良い例:共通のスタイルをmixinで管理
@mixin card-base {
border: 1px solid #ddd;
border-radius: 4px;
padding: 15px;
}
.card {
@include card-base;
background: white;
}
.card-highlighted {
@include card-base;
background: #f8f9fa;
}
// 悪い例:重複したコード
.card {
border: 1px solid #ddd;
border-radius: 4px;
padding: 15px;
background: white;
}
.card-highlighted {
border: 1px solid #ddd; // 重複
border-radius: 4px; // 重複
padding: 15px; // 重複
background: #f8f9fa;
}
パフォーマンス最適化のためのチェックリスト:
| 項目 | 推奨される対策 |
|---|---|
| ファイルサイズ | 不要なmixinを削除、必要最小限の機能に限定 |
| コンパイル時間 | 複雑な計算やネストを避ける |
| キャッシュ活用 | プロダクション環境でのキャッシュを有効化 |
| 選択子の最適化 | 過度なセレクタの連鎖を避ける |
命名規則とファイル構成のベストプラクティス
効率的なプロジェクト管理のための命名規則とファイル構成について解説します。
- ファイル構成の例
styles/ ├── abstracts/ │ ├── _variables.scss # 変数定義 │ ├── _functions.scss # 関数定義 │ ├── _mixins.scss # 共通mixin定義 │ └── _placeholders.scss # プレースホルダー ├── components/ │ ├── _buttons.scss # ボタン関連のmixin │ ├── _cards.scss # カード関連のmixin │ └── _forms.scss # フォーム関連のmixin └── main.scss # メインファイル
- 命名規則の例
// パーシャルファイルの命名
// _component-name.scss の形式を使用
// Mixinの命名規則
@mixin component-name {
// スタイル
}
@mixin component-name-variant {
// バリエーション
}
// 使用例
.c-button {
@include button-base;
}
.c-button--primary {
@include button-variant(primary);
}
ベストプラクティスのまとめ:
- ファイル管理
- 関連するmixinは同じファイルにまとめる
- パーシャルファイルは必ず_(アンダースコア)で始める
- 論理的なディレクトリ構造を維持する
- 命名規則
- BEM方式やSMACSSなどの命名規則に従う
- mixinの名前は機能を明確に表す
- プレフィックスを活用して種類を区別する
- コード品質
- 一貫性のある構文を使用
- コメントで機能を説明する
- 変数を活用して値を管理する
- 保守性
// 良い例:変数を使用した柔軟な設計
$button-padding: 10px 20px !default;
$button-border-radius: 4px !default;
@mixin button-base {
padding: $button-padding;
border-radius: $button-border-radius;
// その他のスタイル
}
// 悪い例:ハードコードされた値
@mixin button-base {
padding: 10px 20px; // 変更が困難
border-radius: 4px; // 変更が困難
// その他のスタイル
}
これらのベストプラクティスを遵守することで、保守性が高く、効率的なSassコードを書くことができます。特にチーム開発では、これらの規則を明文化し、全員で共有することが重要です。
実際のプロジェクトでの活用事例
大規模Railsプロジェクトでの導入事例
大規模なECサイトのリニューアルプロジェクトでの実装例を紹介します。
- テーマシステムの実装
// themes/_theme-manager.scss
@mixin generate-theme($theme-name, $colors) {
.theme-#{$theme-name} {
@each $name, $color in $colors {
--color-#{$name}: #{$color};
}
}
}
// テーマの定義
$theme-default: (
'primary': #007bff,
'secondary': #6c757d,
'accent': #28a745,
'background': #ffffff,
'text': #333333
);
$theme-dark: (
'primary': #0056b3,
'secondary': #495057,
'accent': #1e7e34,
'background': #1a1a1a,
'text': #ffffff
);
// テーマの生成
@include generate-theme('default', $theme-default);
@include generate-theme('dark', $theme-dark);
- コンポーネントライブラリの構築
// components/_product-card.scss
@mixin product-card {
.product-card {
border: 1px solid var(--color-border);
border-radius: 8px;
padding: 16px;
&__image {
@include aspect-ratio(4, 3);
margin-bottom: 12px;
}
&__title {
@include text-ellipsis;
font-size: 1.1rem;
margin-bottom: 8px;
}
&__price {
@include price-format;
color: var(--color-primary);
}
}
}
// 使用例
@include product-card;
保守性を高めるためのリファクタリングの例
既存のプロジェクトをリファクタリングした事例を紹介します。
リファクタリング前:
// Before: 重複が多く、保守が困難なコード
.button-primary {
display: inline-block;
padding: 10px 20px;
border-radius: 4px;
background: #007bff;
color: white;
transition: all 0.3s;
}
.button-secondary {
display: inline-block;
padding: 10px 20px;
border-radius: 4px;
background: #6c757d;
color: white;
transition: all 0.3s;
}
リファクタリング後:
// After: mixinを活用した効率的なコード
@mixin button-base {
display: inline-block;
padding: 10px 20px;
border-radius: 4px;
transition: all 0.3s;
&:hover {
transform: translateY(-1px);
}
}
@mixin button-variant($background) {
background: $background;
color: white;
&:hover {
background: darken($background, 10%);
}
}
.button {
&-primary {
@include button-base;
@include button-variant(#007bff);
}
&-secondary {
@include button-base;
@include button-variant(#6c757d);
}
}
実装の改善ポイント:
| 改善項目 | Before | After | 効果 |
|---|---|---|---|
| コード量 | 重複が多い | DRY原則に従う | 保守性向上 |
| 拡張性 | 変更が困難 | 容易に拡張可能 | 開発効率向上 |
| 再利用性 | 低い | 高い | 一貫性確保 |
プロジェクトでの具体的な成果:
- コードの重複が60%減少
- スタイルの変更時間が75%短縮
- 新機能追加の工数が40%削減
これらの実装例から学べる重要なポイント:
- 段階的な導入
- 既存のコードを一度に書き換えるのではなく、段階的に改善
- 最も効果の高い部分から着手
- チーム開発での活用
- mixinのドキュメント化
- コーディング規約の整備
- レビュー基準の明確化
- メンテナンス性の向上
- 変数の一元管理
- モジュール化による再利用性の向上
- テストのしやすさの改善
これらの事例は、Sass includeの効果的な活用が、実際のプロジェクトでどのように価値を生み出せるかを示しています。
よくあるトラブルとその解決方法
スコープの問題と解決アプローチ
mixinのスコープに関連する一般的な問題とその解決方法を紹介します。
- 変数スコープの問題
// 問題のあるコード
@mixin card-style {
$padding: 15px; // ローカル変数
padding: $padding;
.card-content {
// この変数は外部からアクセス不可
margin: $padding * 2;
}
}
// 解決策
@mixin card-style($padding: 15px) {
// パラメータとして渡す
padding: $padding;
.card-content {
margin: $padding * 2;
}
}
// 使用例
.card {
@include card-style(20px);
}
- セレクタの衝突
// 問題のあるコード
@mixin modal {
.header { // 汎用的すぎる名前
font-size: 1.5rem;
}
}
// 解決策
@mixin modal {
.modal__header { // 明確なスコープ
font-size: 1.5rem;
}
}
コンパイルエラーへの対処法
よく遭遇するコンパイルエラーとその解決方法を解説します。
- 引数の型の不一致
// エラーが発生するケース
@mixin margin-horizontal($value) {
margin-left: $value;
margin-right: $value;
}
.element {
@include margin-horizontal('20px'); // 文字列として渡している
}
// 正しい解決策
@mixin margin-horizontal($value) {
// 型チェックを追加
@if type-of($value) == number {
margin-left: $value;
margin-right: $value;
} @else {
@error "margin-horizontalには数値を指定してください。渡された値: #{$value}";
}
}
.element {
@include margin-horizontal(20px); // 数値として渡す
}
- 存在しない変数の参照
// エラーが発生するケース
@mixin theme-color {
color: $theme-primary; // 未定義の変数
}
// 解決策
@mixin theme-color($color: null) {
// デフォルト値とエラーハンドリングを追加
$theme-primary: #007bff !default;
color: if($color, $color, $theme-primary);
}
よくある問題と解決策のまとめ:
| 問題 | 症状 | 解決策 |
|---|---|---|
| 変数スコープ | 外部から変数にアクセスできない | パラメータとして渡す |
| セレクタ衝突 | 意図しないスタイルの適用 | BEM等の命名規則使用 |
| 型の不一致 | コンパイルエラー | 型チェックの追加 |
| 未定義変数 | コンパイルエラー | デフォルト値の設定 |
デバッグのためのベストプラクティス:
- エラーメッセージの活用
@mixin validate-input($value, $type) {
@if type-of($value) != $type {
@error "Invalid type for #{$value}. Expected #{$type}, got #{type-of($value)}";
}
}
@mixin border-radius($radius) {
@include validate-input($radius, number);
border-radius: $radius;
}
- デバッグ出力
@mixin debug-mixin($name, $params...) {
@if variable-exists(debug-mode) and $debug-mode {
@debug "Mixin #{$name} called with params: #{$params}";
}
}
// 使用例
$debug-mode: true;
@include debug-mixin('border-radius', 5px);
- 条件分岐による防御的プログラミング
@mixin safe-include($property, $value) {
@if not $value {
@warn "No value provided for #{$property}";
} @else {
#{$property}: $value;
}
}
// 使用例
.element {
@include safe-include(margin-top, null); // 警告を出力
@include safe-include(padding, 20px); // 正常に適用
}
これらの解決策を実践することで、より堅牢なSassコードを書くことができます。
次のステップ:さらなる改善のために
パフォーマンス最適化のためのテクニック
より高度なパフォーマンス最適化手法を紹介します。
- スマートなmixinの設計
// パフォーマンスを考慮したmixin
@mixin optimized-box-shadow($level: 1) {
$shadows: (
1: (0 2px 4px rgba(0,0,0,.1)),
2: (0 4px 8px rgba(0,0,0,.1), 0 2px 4px rgba(0,0,0,.1)),
3: (0 8px 16px rgba(0,0,0,.1), 0 4px 8px rgba(0,0,0,.1))
);
@if map-has-key($shadows, $level) {
box-shadow: map-get($shadows, $level);
}
}
// 使用例
.card {
@include optimized-box-shadow(2);
}
- 条件付きインクルード
// 環境に応じた最適化
$environment: production !default;
@mixin debug-styles {
@if $environment != 'production' {
outline: 1px solid red;
&:hover {
outline-color: blue;
}
}
}
// 開発環境でのみデバッグスタイルを適用
.component {
@include debug-styles;
}
新しいSass機能との組み合わせ方
最新のSass機能を活用した高度なテクニックを紹介します。
- モジュールシステムの活用
// _animations.scss
@use 'sass:math';
@mixin keyframe-generator($name, $properties...) {
@keyframes #{$name} {
@for $i from 0 through 100 {
#{$i}% {
@each $prop, $start, $end in $properties {
#{$prop}: mix($start, $end, $i * 1%);
}
}
}
}
}
// 使用例
@include keyframe-generator(
'fade-slide',
(opacity, 0, 1),
(transform, translateY(20px), translateY(0))
);
- 親セレクタの高度な使用
@mixin interactive-states($base-color) {
$states: (
'hover': lighten($base-color, 10%),
'active': darken($base-color, 10%),
'focus': adjust-hue($base-color, 15deg)
);
@each $state, $color in $states {
&:#{$state} {
background-color: $color;
transition: background-color 0.3s ease;
}
}
}
// 使用例
.button {
@include interactive-states(#007bff);
}
今後の発展方向:
| 分野 | 改善ポイント | 期待される効果 |
|---|---|---|
| パフォーマンス | バンドルサイズの最適化 | 読み込み速度向上 |
| モジュール化 | コンポーネントの分離 | 保守性の向上 |
| 型安全性 | 静的解析の導入 | バグの早期発見 |
将来的な展望:
- CSS Custom Propertiesとの連携
@mixin theme-generator($theme-map) {
:root {
@each $key, $value in $theme-map {
--#{$key}: #{$value};
}
}
// ダークモードの自動サポート
@media (prefers-color-scheme: dark) {
:root {
@each $key, $value in map-get($theme-map, 'dark') {
--#{$key}: #{$value};
}
}
}
}
- コンポーネントベースの設計への移行
@mixin component-factory($name, $variants: ()) {
.#{$name} {
@content;
@each $variant, $styles in $variants {
&--#{$variant} {
@each $property, $value in $styles {
#{$property}: $value;
}
}
}
}
}
// 使用例
@include component-factory('button', (
'primary': (
background-color: #007bff,
color: white
),
'secondary': (
background-color: #6c757d,
color: white
)
)) {
padding: 10px 20px;
border-radius: 4px;
}
これらの新しいテクニックを適切に組み合わせることで、より効率的で保守性の高いSassコードを書くことができます。常に新しい機能やベストプラクティスをキャッチアップし、プロジェクトに適用していくことが重要です。