| 両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン |
| css [2013/02/05 11:03] – [nth の指定方法] nullpon | css [2026/02/17 07:11] (現在) – [疑似クラスセレクタ] nullpon |
|---|
| |E[attr$="hoge"]|値がhogeに後方一致するattr属性を持つE要素| | |E[attr$="hoge"]|値がhogeに後方一致するattr属性を持つE要素| |
| |E[attr~="hoge"]|値がhogeであるattr属性を持つE要素、値を複数もつ場合はどれか一つが一致すればよい| | |E[attr~="hoge"]|値がhogeであるattr属性を持つE要素、値を複数もつ場合はどれか一つが一致すればよい| |
| |%%E[attr|="hoge"]%%|値をハイフン区切りし、そのうちどれかがhogeであるattr属性を持つE要素| | |%%E[attr|="hoge"]%%|値が完全一致、もしくは値をハイフンで分割したとき先頭の値がhogeであるattr属性を持つE要素| |
| |
| ==== 疑似クラスセレクタ ==== | ==== 疑似クラスセレクタ ==== |
| |
| |E:root|ルート要素、HTML文書ではhtml要素のこと| | |E:root|ルート要素、HTML文書ではhtml要素のこと、なのでhtml:root以外意味なし、htmlは省略して:rootと記述する| |
| |E:nth-of-type(n)|兄弟要素中のE要素でn番目のもの| | |E:nth-of-type(n)|兄弟要素中のE要素でn番目のもの| |
| |E:nth-last-of-type(n)|兄弟要素中のE要素で後ろからn番目のもの| | |E:nth-last-of-type(n)|兄弟要素中のE要素で後ろからn番目のもの| |
| |E:last-of-type|兄弟要素中のE要素で最後のもの = E:nth-last-of-type(1)| | |E:last-of-type|兄弟要素中のE要素で最後のもの = E:nth-last-of-type(1)| |
| |E:only-of-type|兄弟にE要素がひとつしかない場合、そのE要素| | |E:only-of-type|兄弟にE要素がひとつしかない場合、そのE要素| |
| |E:nth-child(n)|兄弟の中でn番目にあるE要素| | |E:nth-child(n)|兄弟の中でn番目にあるE要素、nth-of-typeとの違いはE以外の要素も含めてn番目であること、つまりn番目がEでなければマッチしない| |
| |E:nth-last-child(n)|兄弟の中で後ろからn番目にあるE要素| | |E:nth-last-child(n)|兄弟の中で後ろからn番目にあるE要素| |
| |E:first-child|兄弟の中で最初の要素であるE| | |E:first-child|兄弟の中で最初の要素であるE| |
| |E::before|E要素の前に生成された空間| | |E::before|E要素の前に生成された空間| |
| |
| | ===== CSS振り分け ===== |
| |
| | [[https://developer.mozilla.org/ja/docs/Web/CSS/Media_Queries/Using_media_queries|メディアクエリの使用 - CSS: カスケーディングスタイルシート | MDN]] |
| |
| | ==== 外観モードによる振り分け ==== |
| | |
| | OSのダークモードへの対応(Firefox 67以降など、2019年3月現在対応ブラウザなし) |
| | |
| | <code html> |
| | <!-- ライトモード、prefers-color-theme未対応の場合のCSS --> |
| | <link rel="stylesheet" href="light.css"> |
| | <!-- ダークモードのCSS --> |
| | <link rel="stylesheet" media="(prefers-color-scheme: dark)" href="dark.css"> |
| | </code> |
| | |
| | ==== iPhone用のview port設定(拡大縮小の禁止設定) ==== |
| |
| ===== CSS振り分け ===== | |
| iPhone用のview port設定(拡大縮小の禁止設定) | |
| <code html> | <code html> |
| <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> | <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> |
| </code> | </code> |
| |
| iPhone、iPad用にCSS振り分け | ==== iPhone、iPad用にCSS振り分け ==== |
| <code html> | <code html> |
| <!-- iPhone --> | <!-- iPhone --> |
| <!-- PC用 --> | <!-- PC用 --> |
| <link rel="stylesheet" media="screen and (min-device-width: 1025px)" href="pc.css"> | <link rel="stylesheet" media="screen and (min-device-width: 1025px)" href="pc.css"> |
| |
| </code> | </code> |
| | |