クラスセレクター .classname { }
クラスセレクターは、特定のクラス属性を持つ要素を指定するセレクターである。
公式サイト:Selectors Level 4#6.6. Class selectors
公式サイト:Selectors Level 3#6.4. Class selectors
公式サイト:5 Selectors(Level 2)#5.8.3 Class selectors
公式サイト:Cascading Style Sheets, level 1#1.4 Class as selector
1. ソースコードの例
.classname {property: value;}.free-name {font-size: 1.2em;}
2. 説明
クラスとIDは大文字と小文字を区別し、英字で始まり、英数字、ハイフン、アンダースコアを含むことができます。クラスは、任意の要素の任意の数のインスタンスに適用することができます。IDは単一の要素にのみ適用することができます。
3. KnotTextでのCSSの分類
2-1. CSSセレクター
2-1-1. ベーシックセレクター
| ユニバーサルセレクタ― | * { } |
|---|---|
| タイプセレクタ― | element { } |
| クラスセレクタ― | .classname { } |
| IDセレクター | #idname { } |
| 属性セレクタ― | selector[attribute] { } |
| セレクターリスト | div, p { } |
|---|
2-1-3. コンビネーター(結合子)
| 子孫結合子 | div a |
|---|---|
| 子結合子 | div > a |
| 一般兄弟結合子 | p ~ a |
| 隣接兄弟結合子 | p + a |
2-1-4. 疑似クラスと疑似要素
| 疑似クラス | div:hover { } |
|---|---|
| 疑似要素 | div::before { } |
2-2. CSSプロパティ
| 3D | perspective, backface-visibilityなど | |
|---|---|---|
| animation | animation, transform, transitionなど | |
| boxmodel | outline, margin, border, padding, background, overflow, z-index, height, width, positionなど | |
| counter | counter-increment, counter-reset, counter-setなど | |
| custom | --* | |
| element | box-shadow, box-sizing, object-fit, object-position, opacity, mix-blend-mode, visibility, content, display, text-overflow, float, clear, empty-cells, caption-side, list-styleなど | |
| graphics | backdrop-filter, filter, shape-image-threashold, shape-margin, scale, image-rendering, aspect-ratio, mask, clip, clip-path, inset, outsetなど | |
| internationalization | line-break, writing-mode, text-orientation, text-combine-upright, direction, unicode-bidi, block-size, inline-sizeなど | |
| layout | column-rule, flex, grid, align-content, align-items, align-self, align-tracks, justify-content, justify-items, justify-self, order, column-count, column-fill, column-gap, columns, column-span, column-width, gap, row-gap, place-content, place-items, place-self, vertical-alignなど | |
| performance | forced-color-adjust, text-rendering, content-visibility, will-change, color-scheme, contain, color-adjustなど | |
| text | word-spacing, text-shadow, text-transform, text-underline-offset, text-underline-position, white-space, shape-outside, text-align, text-align-last, text-indent, text-justify, letter-spacing, line-height, line-height-step, widows, word-break, word-wrap, color, hanging-punctuation, hyphens, initial-letter, orphans, quotes, font, text-decoration, text-emphasis, break-after, break-before, break-insideなど | |
| user-interface | scroll-margin, scroll-padding, overscroll-behavior, user-select, touch-action, caret-color, cursor, resize, pointer-events, scrollbar-color, scrollbar-gutter, scrollbar-width, scroll-behavior, scroll-snap-align, scroll-snap-typeなど | |
| その他のCSSプロパティ | ||
2-3. CSSプロパティの値
| Length | px pt vh... |
|---|---|
| inherit, unset... | |
| !important | |
| Functions | attr(), calc(), clamp(), max(), min()... |
| Angle | deg, grad, rad, turn... |
| Resolution | dpi, dpcm, dppx, x... |
| Time | s, ms... |
| Frequency | Hz, kHz... |
| その他の値 | |
2-4. @ルール
| @font-face | Webフォント |
|---|---|
| @namespace | |
| @media | @media(min-width: 540px) { } |
| @supports | |
| @charset | @charset 'utf-8'; |
| @page | |
| @counter-style | |
| @color-profile | |
| @keyframes | |
| その他の@ルール | |
W3C CSS Validation Service は CSS が正しく書かれているかを判定するために利用できます。デバッグのために重宝するツールです。