:default - CSS: Cascading Style Sheets 编辑

The :default CSS pseudo-class selects form elements that are the default in a group of related elements.

What this selector matches is defined in HTML Standard §4.16.3 Pseudo-classes — it may match the <button>, <input type="checkbox">, <input type="radio">, and <option> elements:

  • A default option element is the first one with the selected attribute, or the first enabled option in DOM order. multiple <select>s can have more than one selected option, so all will match :default.
  • <input type="checkbox"> and <input type="radio"> match if they have the checked attribute.
  • <button> matches if it is a <form>’s default submission button: the first <button> in DOM order that belongs to the form. This also applies to <input> types that submit forms, like image or submit.

Syntax

:default

Examples

HTML

<fieldset>
  <legend>Favorite season</legend>

  <input type="radio" name="season" id="spring">
  <label for="spring">Spring</label>

  <input type="radio" name="season" id="summer" checked>
  <label for="summer">Summer</label>

  <input type="radio" name="season" id="fall">
  <label for="fall">Fall</label>

  <input type="radio" name="season" id="winter">
  <label for="winter">Winter</label>
</fieldset>

CSS

input:default {
  box-shadow: 0 0 2px 1px coral;
}

input:default + label {
  color: coral;
}

Result

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of ':default' in that specification.
Living StandardNo change.
HTML5
The definition of ':default' in that specification.
RecommendationDefines associated HTML semantics and constraint validation.
Selectors Level 4
The definition of ':default' in that specification.
Working DraftNo change.

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:105 次

字数:5264

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文