CSS大百科

CSS大百科|PC☆LIVE!

CSSのプロパティ・セレクター・レスポンシブ設計がわかる一覧表。63項目を用途別に収録。初心者向けの説明と各項目2つの記述例を掲載しています。

文字・フォント

項目 説明 使用例(2例)
color 文字色を変更
color:#1767a1;
/* 文字の色を青に */
color:rebeccapurple;

font-size 文字サイズを指定
font-size:18px;
/* 読みやすい大きさに */
font-size:1.125rem;

font-family 書体を指定
font-family:sans-serif;
/* 日本語フォントを複数指定 */
font-family:"Noto Sans JP",sans-serif;

font-weight 文字の太さ
font-weight:700;
/* 見出しを太字に */
font-weight:bold;

font-style 斜体など
font-style:italic;
/* 強調した文字に */
font-style:normal;

line-height 行の高さ
line-height:1.8;
/* 日本語本文の行間 */
line-height:1.9;

letter-spacing 文字間隔
letter-spacing:.05em;
/* 見出しの文字間隔 */
letter-spacing:1px;

text-align 文章の左右中央寄せ
text-align:center;
/* 本文を左揃え */
text-align:left;

text-decoration 下線や取消線
text-decoration:underline;
/* リンクの下線をなくす */
text-decoration:none;

text-shadow 文字に影を付ける
text-shadow:1px 2px 3px #777;
/* 見出しの奥行きを演出 */
text-shadow:0 2px 4px #0005;

text-transform 英字の大小文字変更
text-transform:uppercase;
/* 先頭だけ大文字 */
text-transform:capitalize;

white-space 改行・空白の扱い
white-space:pre-wrap;
/* コードの改行を保持 */
white-space:nowrap;

word-break 単語の折返し
word-break:break-word;
/* 長い文字列を折り返す */
overflow-wrap:anywhere;

↑ 一覧へ戻る

色・背景・装飾

項目 説明 使用例(2例)
background 背景色や画像をまとめて設定
background:#f2f7fc;
/* 画像と背景色を指定 */
background:linear-gradient(90deg,#125,#39a);

background-color 背景色を指定
background-color:#e8f3ff;
/* カードに淡い背景 */
background-color:aliceblue;

background-image 背景画像やグラデーション
background-image:linear-gradient(120deg,#194b78,#3b91bf);
/* 背景をグラデーションに */
background-image:radial-gradient(circle,#fff,#ddeaff);

background-size 背景画像の大きさ
background-size:cover;
/* 画像全体を収める */
background-size:contain;

background-position 背景画像の位置
background-position:center;
/* 右上基準 */
background-position:right top;

opacity 要素の透明度
opacity:.8;
/* 半透明にする */
opacity:.5;

border 枠線を一括指定
border:1px solid #bdd0e0;
/* 破線の枠 */
border:2px dashed #2682ad;

border-radius 角を丸くする
border-radius:12px;
/* 丸いボタン */
border-radius:999px;

box-shadow ボックスに影を付ける
box-shadow:0 4px 16px #1234;
/* ふんわりした影 */
box-shadow:0 8px 24px #0012;

outline フォーカスの輪郭
outline:2px solid #126fbb;
/* キー操作時の見やすい輪郭 */
outline-offset:3px;

filter ぼかし・明るさ等
filter:grayscale(1);
/* 少し明るく表示 */
filter:brightness(1.1);

↑ 一覧へ戻る

余白・大きさ

項目 説明 使用例(2例)
margin 外側の余白
margin:16px;
/* 上下と左右を分ける */
margin:12px auto;

padding 内側の余白
padding:16px;
/* ボタンを押しやすくする */
padding:12px 20px;

width 横幅を指定
width:100%;
/* 横幅を最大600pxまで */
width:min(100%,600px);

height 高さを指定
height:240px;
/* 画面高さの一部 */
height:50vh;

max-width 最大の横幅
max-width:1100px;
/* PCで広がり過ぎない */
max-width:70rem;

min-height 最小の高さ
min-height:48px;
/* 押しやすいボタン */
min-height:44px;

box-sizing サイズ計算方式
box-sizing:border-box;
/* 幅に余白を含める */
box-sizing:border-box;

aspect-ratio 縦横比
aspect-ratio:16/9;
/* 正方形の画像 */
aspect-ratio:1;

overflow はみ出した部分の表示
overflow:hidden;
/* 横方向のみスクロール */
overflow-x:auto;

object-fit 画像の収まり方
object-fit:cover;
/* 画像を切らずに全体表示 */
object-fit:contain;

↑ 一覧へ戻る

配置・レイアウト

項目 説明 使用例(2例)
display 表示形式を変更
display:flex;
/* 格子状に並べる */
display:grid;

flex-direction Flexの並ぶ方向
flex-direction:column;
/* 横並びにする */
flex-direction:row;

justify-content 主軸方向の配置
justify-content:space-between;
/* 中央に配置 */
justify-content:center;

align-items 交差軸方向の配置
align-items:center;
/* 上揃えにする */
align-items:flex-start;

gap 要素同士の間隔
gap:12px;
/* 行と列で分けて指定 */
gap:12px 20px;

flex-wrap 折り返すかどうか
flex-wrap:wrap;
/* 一列を維持 */
flex-wrap:nowrap;

flex Flex項目の伸縮
flex:1;
/* 伸縮と基本幅を指定 */
flex:1 1 240px;

grid-template-columns Gridの列指定
grid-template-columns:repeat(2,1fr);
/* 自動で列数を調整 */
grid-template-columns:repeat(auto-fit,minmax(220px,1fr));

grid-column 列の占有範囲
grid-column:span 2;
/* 全列をまたぐ */
grid-column:1/-1;

position 配置方法
position:sticky;
/* 画面下に固定 */
position:fixed;

top 上からの位置
top:0;
/* 固定したヘッダー */
top:12px;

bottom 下からの位置
bottom:0;
/* 下部固定メニュー */
bottom:env(safe-area-inset-bottom);

z-index 重なり順
z-index:100;
/* メニューを前面へ */
z-index:999;

inset 上下左右をまとめて指定
inset:0;
/* 上下左右に余白 */
inset:12px;

transform 移動・回転・拡大縮小
transform:translateY(-4px);
/* 少し拡大 */
transform:scale(1.05);

↑ 一覧へ戻る

動き・操作・レスポンシブ

項目 説明 使用例(2例)
transition 変化を滑らかに
transition:opacity .2s;
/* 色の変化を滑らかに */
transition:background .25s ease;

animation アニメーションを指定
animation:fade .5s ease;
/* 別途@keyframesを定義 */
animation:slide .4s both;

cursor マウスカーソル
cursor:pointer;
/* 入力禁止を示す */
cursor:not-allowed;

pointer-events ポインター操作可否
pointer-events:none;
/* クリックを受け付ける */
pointer-events:auto;

scroll-behavior スクロールの動き
scroll-behavior:smooth;
/* 通常に戻す */
scroll-behavior:auto;

scroll-margin-top アンカー先の上余白
scroll-margin-top:80px;
/* 固定ヘッダー対策 */
scroll-margin-top:5rem;

touch-action タッチ操作の許可
touch-action:pan-y;
/* 両方向の移動を許可 */
touch-action:auto;

user-select 文字の選択を制御
user-select:none;
/* テキストを選択可能に */
user-select:text;

@media 画面幅などで条件分岐
@media(min-width:768px){.grid{display:grid;}}
/* PCだけ幅を変える */
@media(min-width:1024px){.page{max-width:1100px;}}

@supports 機能の対応状況で分岐
@supports(display:grid){.list{display:grid;}}
/* 未対応環境への配慮 */
@supports not (display:grid){.list{display:block;}}

:focus-visible キーボード操作時の見た目
button:focus-visible{outline:3px solid #39f;}
/* アクセシビリティ向上 */
a:focus-visible{outline:2px solid #267ac0;}

:hover マウスを乗せたとき
a:hover{color:#b45;}
/* ボタン背景の変更 */
button:hover{background:#def;}

:root ページ全体の基準・変数
:root{--main:#1766a4;}
/* 変数を読み込む */
h2{color:var(--main);}

@keyframes 動きの中身を定義
@keyframes fade{from{opacity:0}to{opacity:1}}
/* 左右に移動 */
@keyframes slide{from{transform:translateX(-10px)}to{transform:translateX(0)}}

↑ 一覧へ戻る

Verified by MonsterInsights
メニュー閉じる