mcpField
C
css

css

github.com/jaredlanderデザイン・UI091 回インストール41 週間前に更新
リポジトリ

css について

モダンでレスポンシブ、保守しやすい CSS の作成を支援するスキルガイドです。ブラウザー互換性とパフォーマンスを重視し、プロパティや仕様の確認には context7 を推奨します。

主な機能

  1. 01モバイルファーストのレスポンシブ設計
  2. 02Flexbox、Grid、コンテナークエリー
  3. 03モダンなセレクターとアニメーション
  4. 04パフォーマンス、アクセシビリティ、互換性
  5. 05context7 によるドキュメント検索

活用シーン

  1. 01画面サイズに応じたレイアウトの設計
  2. 02CSS の構文とブラウザー対応状況の確認
  3. 03アニメーションやスタイルの性能改善

MCP 対応

CSS のドキュメント、仕様の詳細、ブラウザー互換性を調べる際に context7 MCP ツールを使うよう案内しています。

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/jaredlander/freshbooks-speed --skill css

インストール後、Claude Code で/cssを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

references/
accessibility.md
layout.md
modern-features.md
performance.md

詳細

エキスパート向けCSS開発

最新のベストプラクティスに従い、ブラウザー互換性とCSS仕様に関する深い知識を活かして、モダンで高性能かつ保守しやすいCSSを記述します。

context7を使ったドキュメントの検索

重要:CSSプロパティ、構文、ブラウザー互換性、仕様の詳細を調べる必要がある場合は、context7 MCPツールを使ってMDNなどのドキュメントソースを検索してください。

CSSでのcontext7の使い方
# Look up CSS properties
context7 "CSS flexbox properties"
context7 "CSS grid-template-areas syntax"
context7 "CSS custom properties inheritance"

# Check browser compatibility
context7 "CSS container queries browser support"
context7 "CSS :has() selector compatibility"

# Find best practices
context7 "CSS performance optimization"
context7 "CSS naming conventions BEM"

# Explore modern features
context7 "CSS cascade layers @layer"
context7 "CSS subgrid"
context7 "CSS color-mix function"

次の場合は常にcontext7を使用してください:

  • 正確な構文やプロパティ値がわからない場合
  • 機能のブラウザーサポートを確認する必要がある場合
  • 最新のベストプラクティスを調べたい場合
  • 先進的なCSS機能を扱う場合
  • 仕様の詳細や特殊なケースを理解する必要がある場合

基本原則

  1. モバイルファーストのレスポンシブデザイン - モバイル向けのレイアウトから始め、段階的に拡張します
  2. プログレッシブエンハンスメント - 基本機能はどこでも動作するようにし、対応環境では機能を強化します
  3. CSSカスケードと詳細度 - 仕組みを理解して活用し、無理に対抗しないようにします
  4. パフォーマンスを重視 - リフローを最小限に抑え、アニメーションを最適化し、ファイルサイズを削減します
  5. 保守性 - 一貫した命名、論理的な構成、明確なドキュメントを使用します

モダンなレイアウト手法

1次元レイアウトにはFlexbox
/* Common flex patterns */
.container {
  display: flex;
  gap: 1rem; /* Prefer gap over margins for spacing */
}

/* Center content */
.centered {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Responsive flex wrapping */
.flex-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.flex-wrap > * {
  flex: 1 1 300px; /* Grow, shrink, basis */
}

/* Common flex utilities */
.flex-1 { flex: 1; }
.flex-none { flex: none; }
.flex-auto { flex: auto; }
2次元レイアウトにはGrid
/* Responsive grid with auto-fit */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 2rem;
}

/* Named grid areas for semantic layouts */
.layout {
  display: grid;
  grid-template-areas:
    "header header"
    "sidebar main"
    "footer footer";
  grid-template-columns: 250px 1fr;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.footer { grid-area: footer; }

/* Dense packing for masonry-like layouts */
.masonry {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  grid-auto-flow: dense;
  gap: 1rem;
}
コンテナークエリ(メディアクエリに代わるモダンな手法)
/* Container query setup */
.card-container {
  container-type: inline-size;
  container-name: card;
}

/* Query the container, not the viewport */
@container card (min-width: 400px) {
  .card {
    display: grid;
    grid-template-columns: 150px 1fr;
  }
}

@container card (min-width: 600px) {
  .card {
    grid-template-columns: 200px 1fr;
  }
}

モダンなCSS機能

カスタムプロパティ(CSS変数)
:root {
  /* Color system */
  --color-primary: #0066cc;
  --color-primary-dark: #004499;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  
  /* Spacing scale */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 2rem;
  --space-xl: 4rem;
  
  /* Typography */
  --font-sans: system-ui, -apple-system, sans-serif;
  --font-mono: 'Fira Code', monospace;
  
  /* Dark mode using data attribute */
  --bg: var(--color-surface);
  --fg: var(--color-text);
}

[data-theme="dark"] {
  --color-surface: #1a1a1a;
  --color-text: #e5e5e5;
}

/* Using custom properties */
.button {
  background: var(--color-primary);
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-sans);
}
カスケードレイヤー(@layer)
/* Define layer order - lowest specificity first */
@layer reset, base, components, utilities;

@layer reset {
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
}

@layer base {
  body {
    font-family: system-ui, sans-serif;
    line-height: 1.5;
  }
}

@layer components {
  .button {
    padding: 0.5rem 1rem;
    border-radius: 0.25rem;
  }
}

@layer utilities {
  .text-center { text-align: center; }
  .hidden { display: none; }
}
モダンなセレクター
/* :is() for grouping (no specificity increase) */
:is(h1, h2, h3) {
  font-weight: 700;
  line-height: 1.2;
}

/* :where() for zero specificity */
:where(.card, .panel) > :where(h2, h3) {
  margin-top: 0;
}

/* :has() for parent selection */
.card:has(img) {
  display: grid;
  grid-template-columns: 200px 1fr;
}

.form:has(:invalid) .submit-button {
  opacity: 0.5;
  pointer-events: none;
}

/* Logical properties for internationalization */
.element {
  margin-inline-start: 1rem; /* Instead of margin-left */
  padding-block: 2rem; /* Instead of padding-top and padding-bottom */
  border-inline-end: 1px solid; /* Instead of border-right */
}

アニメーションとトランジション

高性能なアニメーション
/* Only animate transform and opacity for 60fps */
.smooth-animation {
  /* Hint to browser for optimization */
  will-change: transform;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.smooth-animation:hover {
  transform: translateY(-4px);
}

/* Remove will-change after animation */
.smooth-animation:not(:hover) {
  will-change: auto;
}

/* Complex keyframe animations */
@keyframes slideInFade {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-in {
  animation: slideInFade 0.4s ease-out;
}
View Transitions API
/* Smooth page transitions */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.3s;
}

/* Named transitions for specific elements */
.hero {
  view-transition-name: hero-image;
}

::view-transition-old(hero-image),
::view-transition-new(hero-image) {
  animation-duration: 0.5s;
}
スクロール駆動アニメーション
/* Animate on scroll progress */
@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(50px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.scroll-reveal {
  animation: fade-in linear;
  animation-timeline: view();
  animation-range: entry 0% cover 30%;
}

レスポンシブデザインのパターン

モダンなメディアクエリの戦略
/* Mobile-first approach */
.component {
  /* Base mobile styles */
  padding: 1rem;
}

/* Tablet */
@media (min-width: 768px) {
  .component {
    padding: 2rem;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .component {
    padding: 3rem;
  }
}

/* Wide desktop */
@media (min-width: 1440px) {
  .component {
    padding: 4rem;
  }
}

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Dark mode preference */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --fg: #e5e5e5;
  }
}
可変フォントサイズ
/* Clamp for responsive font sizes */
h1 {
  font-size: clamp(2rem, 4vw + 1rem, 4rem);
}

body {
  font-size: clamp(1rem, 0.5vw + 0.875rem, 1.125rem);
}

/* Or using custom properties */
:root {
  --fluid-min-width: 320;
  --fluid-max-width: 1140;
  --fluid-min-size: 16;
  --fluid-max-size: 20;
  
  --fluid-size: calc(
    (var(--fluid-min-size) * 1px) +
    (var(--fluid-max-size) - var(--fluid-min-size)) *
    ((100vw - (var(--fluid-min-width) * 1px)) /
    (var(--fluid-max-width) - var(--fluid-min-width)))
  );
}

body {
  font-size: clamp(
    var(--fluid-min-size) * 1px,
    var(--fluid-size),
    var(--fluid-max-size) * 1px
  );
}

パフォーマンスの最適化

パフォーマンスに関する重要なルール
/* 1. Avoid expensive properties */
.avoid {
  box-shadow: ...; /* OK, GPU accelerated */
  filter: ...; /* Expensive, use sparingly */
}

/* 2. Use containment for isolated components */
.card {
  contain: layout style paint;
  /* Tells browser this element's styles won't affect others */
}

.isolated-component {
  content-visibility: auto; /* Skip rendering offscreen elements */
}

/* 3. Optimize selectors - specificity vs performance */
/* Fast ✅ */
.button { }
.nav-item { }

/* Slower ❌ */
div.container ul li a.link { }
[class*="btn-"] { }
CSSの読み込み戦略

<style>
  /* Above-the-fold styles */
</style>


<link rel="stylesheet" href="styles.css" media="print" onload="this.media='all'">


<link rel="preload" href="fonts.woff2" as="font" type="font/woff2" crossorigin>

命名規則と構成

BEM(ブロック・エレメント・モディファイア)
/* Block */
.card { }

/* Element - part of block */
.card__title { }
.card__body { }
.card__footer { }

/* Modifier - variation of block */
.card--featured { }
.card--large { }
.card__title--primary { }
ユーティリティファースト(Tailwindスタイル)
/* Spacing utilities */
.p-4 { padding: 1rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.mt-2 { margin-top: 0.5rem; }

/* Layout utilities */
.flex { display: flex; }
.grid { display: grid; }
.hidden { display: none; }

/* Typography utilities */
.text-lg { font-size: 1.125rem; }
.font-bold { font-weight: 700; }
.text-center { text-align: center; }
ファイル構成
styles/
├── base/
│   ├── reset.css
│   ├── typography.css
│   └── utilities.css
├── components/
│   ├── button.css
│   ├── card.css
│   └── nav.css
├── layout/
│   ├── grid.css
│   ├── header.css
│   └── footer.css
├── themes/
│   ├── light.css
│   └── dark.css
└── main.css (imports all)

モダンな色関数

:root {
  /* Modern color functions */
  --primary: oklch(60% 0.2 250); /* Perceptually uniform */
  --surface: color-mix(in oklch, var(--primary) 10%, white);
  
  /* Relative colors */
  --primary-light: oklch(from var(--primary) calc(l + 20%) c h);
  --primary-dark: oklch(from var(--primary) calc(l - 20%) c h);
  
  /* Color contrast for accessibility */
  --text-color: color-contrast(
    var(--surface) vs black, white
  );
}

ブラウザー互換性の戦略

機能クエリ(@supports)
/* Fallback for older browsers */
.grid {
  display: flex;
  flex-wrap: wrap;
}

/* Enhanced for modern browsers */
@supports (display: grid) {
  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }
}

/* Progressive enhancement */
.button {
  background: blue;
}

@supports (backdrop-filter: blur(10px)) {
  .button {
    background: rgba(0, 0, 255, 0.8);
    backdrop-filter: blur(10px);
  }
}

よく使われるパターンと解決策

アスペクト比
/* Modern way */
.video {
  aspect-ratio: 16 / 9;
}

/* For images */
img {
  aspect-ratio: 16 / 9;
  object-fit: cover;
}
テキストの省略
/* Single line */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Multiple lines */
.line-clamp {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
スムーズスクロール
html {
  scroll-behavior: smooth;
}

/* Scroll snapping */
.carousel {
  scroll-snap-type: x mandatory;
  overflow-x: auto;
}

.carousel > * {
  scroll-snap-align: start;
}

アクセシビリティに関する考慮事項

/* Focus visible for keyboard users only */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Hide visually but keep for screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Respect user preferences */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (prefers-contrast: high) {
  .button {
    border: 2px solid currentColor;
  }
}

CSSリセット/Normalize

/* Modern CSS reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  line-height: 1.5;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
}

クイックリファレンス

詳しいガイドについては、references/を参照してください:

  • モダンなレイアウト手法(flexbox、grid、コンテナークエリ)
  • アニメーションとトランジションのベストプラクティス
  • パフォーマンス最適化の戦略
  • レスポンシブデザインのパターン
  • アクセシビリティのガイドライン

ワークフロー

  1. まずcontext7を使う - 不慣れなプロパティやモダンな機能を調べます
  2. モバイルファースト - モバイル向けに設計・コーディングし、大きな画面向けに拡張します
  3. 機能クエリを使う - @supportsによるプログレッシブエンハンスメントを行います
  4. 複数のブラウザーでテストする - Chrome、Firefox、Safari、Edgeで確認します
  5. 検証する - 標準への準拠をW3C CSS Validatorで確認します
  6. 最適化する - リフローを最小限に抑え、containを使い、GPUアクセラレーションを活用します
  7. ドキュメントを作成する - 複雑な計算、マジックナンバー、ブラウザーハックにコメントを付けます

ツールとリソース

  • context7 - 主に使用するドキュメント検索ツール
  • MDN Web Docs - 包括的なCSSリファレンス(context7経由)
  • Can I Use - ブラウザー互換性のデータ(context7経由)
  • CSS Specifications - 動作の詳細を確認できるW3C仕様(context7経由)
  • PostCSS - JavaScriptプラグインでCSSを変換します
  • CSS Modules - コンポーネント向けのスコープ付きCSS
  • Sass/SCSS - 変数、ネスト、ミックスインを備えたCSSプリプロセッサー
  • Lightning CSS - 高速なCSSパーサー、トランスフォーマー、ミニファイアー

覚えておいてください:CSSの機能、構文、ブラウザーサポートに少しでも不明な点があれば、context7を使って最新のドキュメントを調べてください。

コメント