CSSチートシート|初心者でもすぐに使える基本プロパティと便利テクまとめ

CSS

Webデザインを始めたばかりの頃、CSSの書き方やプロパティが多すぎて「何をどう使えばいいのかわからない!」と困った経験はありませんか?

「あの効果、どうやって作るんだっけ?」

「よく使うプロパティを忘れてしまう…」

「効率よくCSSを書けるようになりたい」

そんなときに便利なのがCSSチートシートです。

よく使うプロパティや書き方をまとめておくことで、コードを書くときにすぐ確認でき、効率がぐっとアップします。

この記事では、初心者でも迷わず使えるように

  • レイアウト(flexbox、position など)
  • 文字デザイン(フォント、色、配置など)
  • 余白調整(margin、padding)
  • ボックスデザイン(背景、枠線、影など)
  • アニメーション(hover効果、動きなど)

まで、CSSでよく使う基本&便利プロパティを、コピペで使える例文とともに一覧で紹介します。

スポンサーリンク

このチートシートの使い方

効率的な活用方法

  • ブックマーク推奨: この記事をブックマークして、コーディング中に参照
  • 段階的学習: 全部覚えようとせず、必要な部分から徐々に使用
  • 実践重視: 実際にコードを書きながら確認

カテゴリ別の優先度

  • 最優先: レイアウト、文字デザイン、余白調整
  • 次に重要: ボックスデザイン、基本アニメーション
  • 応用編: 高度なアニメーション、特殊効果

1. レイアウト調整に使うCSS

Flexbox(最重要)

プロパティ効果
displaydisplay: flex;flexboxレイアウトを開始
justify-contentjustify-content: center;横方向の配置(center, space-between, flex-end など)
align-itemsalign-items: center;縦方向の配置(center, flex-start, flex-end など)
flex-directionflex-direction: column;縦並びに変更(デフォルトは row)
flex-wrapflex-wrap: wrap;要素を折り返し可能にする
gapgap: 20px;要素間の間隔を一括指定
flexflex: 1;余ったスペースを均等に分割

よく使う組み合わせ:

/* 中央寄せ */
.center {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* 横並び・均等間隔 */
.spread {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* カード並び */
.cards {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

Position(位置調整)

プロパティ効果
positionposition: relative;位置指定の基準を設定
position: absolute;親要素を基準に自由配置
position: fixed;画面に固定(スクロールしても動かない)
position: sticky;スクロール時に指定位置で固定
toptop: 10px;上からの距離
rightright: 15px;右からの距離
bottombottom: 0;下からの距離
leftleft: 20px;左からの距離
z-indexz-index: 10;重なり順序(数字が大きいほど前面)

実用例:

/* 右上に固定ボタン */
.fixed-button {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
}

/* 中央配置 */
.absolute-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

CSS Grid(格子レイアウト)

プロパティ効果
displaydisplay: grid;gridレイアウトを開始
grid-template-columnsgrid-template-columns: 1fr 1fr 1fr;列の分割(3等分の例)
grid-template-rowsgrid-template-rows: auto 1fr auto;行の分割
grid-gapgrid-gap: 20px;グリッド間の間隔
grid-columngrid-column: span 2;2列分のスペースを占有
grid-rowgrid-row: span 3;3行分のスペースを占有

実用例:

/* 基本的な3カラムレイアウト */
.grid-layout {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
}

/* レスポンシブ対応グリッド */
.responsive-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

2. 文字デザインに使うCSS

基本の文字プロパティ

プロパティ効果
font-sizefont-size: 16px;文字サイズ(px, em, rem, % が使える)
colorcolor: #333;文字色(#hex, rgb(), 色名 が使える)
font-familyfont-family: 'Arial', sans-serif;フォント指定
font-weightfont-weight: bold;太さ(normal, bold, 100-900 の数値)
font-stylefont-style: italic;斜体(normal, italic)
text-decorationtext-decoration: underline;装飾(underline, line-through, none)
text-transformtext-transform: uppercase;大文字変換(uppercase, lowercase, capitalize)

文字配置・間隔

プロパティ効果
text-aligntext-align: center;横方向の配置(left, center, right, justify)
line-heightline-height: 1.6;行間(1.5-1.8 が読みやすい)
letter-spacingletter-spacing: 0.1em;文字間隔
word-spacingword-spacing: 0.2em;単語間隔
text-indenttext-indent: 1em;段落の字下げ
vertical-alignvertical-align: middle;縦方向の配置(テーブルセルやインライン要素)

実用例:

/* 見出しスタイル */
.heading {
  font-size: 24px;
  font-weight: bold;
  color: #333;
  text-align: center;
  letter-spacing: 0.05em;
}

/* 読みやすい本文 */
.text-body {
  font-size: 16px;
  line-height: 1.7;
  color: #555;
  text-align: justify;
}

文字の切り抜き・省略

プロパティ効果
white-spacewhite-space: nowrap;改行を防ぐ
overflowoverflow: hidden;はみ出しを隠す
text-overflowtext-overflow: ellipsis;省略記号(…)を表示

文字省略の組み合わせ:

/* 1行で省略 */
.text-ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 複数行で省略(Webkit系ブラウザ) */
.text-clamp {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

3. 余白調整(マージン・パディング)

基本的な余白プロパティ

プロパティ効果
marginmargin: 20px;外側の余白(全方向)
paddingpadding: 10px;内側の余白(全方向)
margin-topmargin-top: 15px;上の外側余白
margin-rightmargin-right: 10px;右の外側余白
margin-bottommargin-bottom: 25px;下の外側余白
margin-leftmargin-left: 5px;左の外側余白
padding-toppadding-top: 8px;上の内側余白
padding-rightpadding-right: 12px;右の内側余白
padding-bottompadding-bottom: 8px;下の内側余白
padding-leftpadding-left: 12px;左の内側余白

便利な余白指定方法

書き方効果
4方向個別margin: 10px 15px 20px 5px;上 右 下 左 の順
上下・左右margin: 10px 20px;上下10px、左右20px
上・左右・下margin: 5px 10px 15px;上5px、左右10px、下15px
中央寄せmargin: 0 auto;左右を自動調整(中央寄せ)

実用例:

/* カードのスタイル */
.card {
  margin: 20px auto;  /* 上下20px、左右中央寄せ */
  padding: 15px 20px; /* 上下15px、左右20px */
  max-width: 400px;
}

/* ボタンのスタイル */
.button {
  padding: 12px 24px;  /* 上下12px、左右24px */
  margin-bottom: 10px; /* 下に10pxの間隔 */
}

4. ボックスデザインを整えるCSS

サイズ調整

プロパティ効果
widthwidth: 300px;幅を指定
heightheight: 200px;高さを指定
max-widthmax-width: 100%;最大幅を制限
min-widthmin-width: 200px;最小幅を指定
max-heightmax-height: 500px;最大高さを制限
min-heightmin-height: 100px;最小高さを指定
box-sizingbox-sizing: border-box;padding/borderを含めたサイズ計算

背景デザイン

プロパティ効果
background-colorbackground-color: #f5f5f5;背景色
background-imagebackground-image: url('image.jpg');背景画像
background-sizebackground-size: cover;背景画像のサイズ(cover, contain, 100% など)
background-positionbackground-position: center;背景画像の位置
background-repeatbackground-repeat: no-repeat;背景画像の繰り返し
backgroundbackground: #fff url('bg.jpg') center/cover no-repeat;背景の一括指定

枠線とエフェクト

プロパティ効果
borderborder: 1px solid #ccc;枠線(太さ スタイル 色)
border-topborder-top: 2px solid #333;上の枠線のみ
border-radiusborder-radius: 8px;角を丸くする
box-shadowbox-shadow: 2px 2px 5px rgba(0,0,0,0.2);影をつける
outlineoutline: 2px solid #007bff;アウトライン(レイアウトに影響しない枠線)

実用例:

/* カードデザイン */
.modern-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  padding: 20px;
  margin: 20px 0;
}

/* ボタンデザイン */
.primary-button {
  background: #007bff;
  border: none;
  border-radius: 6px;
  color: white;
  padding: 12px 24px;
  box-shadow: 0 2px 4px rgba(0,123,255,0.3);
}

表示・非表示

プロパティ効果
displaydisplay: none;要素を完全に隠す
display: block;ブロック要素として表示
display: inline;インライン要素として表示
display: inline-block;インラインブロック要素として表示
visibilityvisibility: hidden;要素を透明にする(場所は確保)
opacityopacity: 0.5;透明度を調整(0-1)
overflowoverflow: hidden;はみ出し部分を隠す
overflow: scroll;スクロールバーを表示
overflow: auto;必要に応じてスクロールバー

5. アニメーション・動きを作るCSS

基本のアニメーション

プロパティ効果
transitiontransition: all 0.3s ease;変化をなめらかに(プロパティ 時間 変化方法)
transformtransform: scale(1.1);拡大縮小・回転・移動
cursorcursor: pointer;カーソルの形を変更

Transformの値

変形効果
scale()transform: scale(1.2);1.2倍に拡大
rotate()transform: rotate(45deg);45度回転
translate()transform: translate(10px, 20px);X軸に10px、Y軸に20px移動
skew()transform: skew(15deg);傾斜変形

キーフレームアニメーション

/* アニメーションの定義 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* アニメーションの適用 */
.fade-in {
  animation: fadeIn 0.5s ease-out;
}

よく使うHover効果

/* ボタンのホバー効果 */
.hover-button {
  background: #007bff;
  color: white;
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  transition: all 0.3s ease;
  cursor: pointer;
}

.hover-button:hover {
  background: #0056b3;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,123,255,0.3);
}

/* カードのホバー効果 */
.hover-card {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.hover-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

6. 便利なユーティリティ・その他

よく使う便利プロパティ

プロパティ効果
cursorcursor: pointer;カーソルを手の形にする
user-selectuser-select: none;テキスト選択を無効化
pointer-eventspointer-events: none;クリックを無効化
resizeresize: none;要素のリサイズを無効化
scroll-behaviorscroll-behavior: smooth;スムーズスクロール

画像関連

プロパティ効果
object-fitobject-fit: cover;画像をはみ出さずに切り抜く
object-fit: contain;画像全体を表示
object-positionobject-position: center top;画像の位置調整
filterfilter: blur(5px);ぼかし効果
filter: brightness(1.2);明度調整
filter: grayscale(100%);グレースケール

レスポンシブ対応

/* モバイルファースト */
.responsive-text {
  font-size: 14px;
}

/* タブレット以上 */
@media (min-width: 768px) {
  .responsive-text {
    font-size: 16px;
  }
}

/* デスクトップ以上 */
@media (min-width: 1024px) {
  .responsive-text {
    font-size: 18px;
  }
}

7. 実用的なコンポーネント例

モダンなカードコンポーネント

.card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  padding: 24px;
  margin: 16px 0;
  transition: all 0.3s ease;
  border: 1px solid #e5e7eb;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}

.card-title {
  font-size: 20px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 12px;
}

.card-content {
  color: #6b7280;
  line-height: 1.6;
}

フレックスボックスナビゲーション

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.nav-brand {
  font-size: 24px;
  font-weight: bold;
  color: #1f2937;
}

.nav-menu {
  display: flex;
  gap: 32px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-link {
  color: #6b7280;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.3s ease;
}

.nav-link:hover {
  color: #3b82f6;
}

レスポンシブグリッド

.grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  padding: 24px;
}

.grid-item {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

まとめ:効率的なCSS開発のために

このチートシートを活用するコツ

段階的習得:

  1. レイアウト(flexbox)を最初にマスター
  2. 文字デザインと余白調整で見た目を整える
  3. ボックスデザインでコンポーネントを作る
  4. アニメーションで動きをつける

実践的な使い方:

  • よく使うパターンは自分用のスニペット集を作成
  • プロジェクトごとに必要なプロパティを厳選
  • ブラウザの開発者ツールで効果を確認しながら調整

覚えておくべき最重要プロパティ

  • レイアウト: display: flex, justify-content, align-items
  • 文字: font-size, color, text-align, line-height
  • 余白: margin, padding デザイン: background, border, border-radius, box-shadow
  • アニメーション: transition, transform, cursor: pointer

コメント

タイトルとURLをコピーしました