The :default pseudo-class matches the default element in a group of associated elements, such as the radio button in a group of buttons that are selected by default, even if the user has selected a different value.
Syntax
:default { css declarations; }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Input pseudo-classes</title> <style> input:default + label { color: brown; } option:default { color: green; font-weight: bold; } </style> </head> <body> <h3>Input pseudo-classes</h3> <p>:default</p> <input type="checkbox" id="c" checked /> <label for="c">C Program</label> <br /> <input type="checkbox" id="cpp" /> <label for="cpp">C++</label> <br /> <input type="checkbox" id="java" /> <label for="java">Java</label> <br /> <hr /> <input type="radio" id="male" checked name="gender" /> <label for="male">Male</label> <br /> <input type="radio" id="female" name="gender" /> <label for="female">Female</label> <br /> <hr /> <label for="course">Course Name</label> <select id="course"> <option value="">Select Value</option> <option value="c">C</option> <option value="cpp" selected>C++</option> <option value="java">Java</option> </select> </body> </html>
The provided CSS code is used to style HTML <input> elements and <option> elements based on their default state. It applies different styles to these elements when they are considered "default."
input:default + label: This selector targets <label> elements that are immediately adjacent (sibling) to <input> elements when those input elements are in their default state.
option:default: This selector targets <option> elements within a <select> element when those options are in their default state.
It's important to note that the concept of a "default" state for <input> elements and <option> elements is context-specific and may depend on user interactions or the initial state of the form. The styles applied in this code help differentiate these elements when they are in their default states from when they are in other states.
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions