:default
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2020年1月.
試してみましょう
label, input[type="submit"] { display: block; margin-top: 1em; } input:default { border: none; outline: 2px solid deeppink; } <form> <p>どのように私たちを知りましたか?</p> <label ><input name="origin" type="radio" value="google" checked /> Google</label > <label><input name="origin" type="radio" value="facebook" /> Facebook</label> <p>利用規約に同意してください。</p> <label ><input name="newsletter" type="checkbox" checked /> パーソナライズされたニュースレターを購読したいです。</label > <label ><input name="privacy" type="checkbox" />プライバシーポリシーをを読み、同意します。</label > <input type="submit" value="送信フォーム" /> </form> このセレクターが何に一致するかについては、 HTML Standard §4.16.3 Pseudo-classes で定義されています。 — <button>、<input type="checkbox">、<input type="radio">、<option> 要素に一致させることができます。
- 既定の option 要素は
selected属性が付いた最初のもの、または DOM 順で最初の有効な選択肢です。multipleが付いた<select>は、複数のselectedがついた選択肢を持つことができますので、すべてが:defaultに一致します。 <input type="checkbox">と<input type="radio">はchecked属性があるときに一致します。<button>は<form>の 既定の送信ボタンである場合に一致します。フォームに所属する<button>のうち、 DOM 順で最初のものです。これはフォームを送信する<input>型、例えばimageまたはsubmitにも適用されます。
構文
css
:default { /* ... */ } 例
>HTML
html
<fieldset> <legend>好きな季節</legend> <input type="radio" name="season" id="spring" value="spring" /> <label for="spring">春</label> <input type="radio" name="season" id="summer" value="summer" checked /> <label for="summer">夏</label> <input type="radio" name="season" id="fall" value="fall" /> <label for="fall">秋</label> <input type="radio" name="season" id="winter" value="winter" /> <label for="winter">冬</label> </fieldset> CSS
css
input:default { box-shadow: 0 0 2px 1px coral; } input:default + label { color: coral; } 結果
仕様書
| Specification |
|---|
| HTML> # selector-default> |
| Selectors Level 4> # default-pseudo> |