Selecting Checked Elements

Description

Radio buttons and check boxes that are checked can be selected through the :checked selector.

Example

The following code uses the :checked Selector.


<!DOCTYPE HTML>
<html>
<head>
<style>
:checked+span {<!--from   w w w  .j  a va 2s  .c  o  m-->
  background-color: red;
  color: white;
  padding: 5px;
  border: medium solid black;
}
</style>
</head>
<body>
  <form method="post" action="http://example.com/form">
    <p>
      <label for="apples">Select:</label>
      <input type="checkbox" id="myID" name="XML" />
      <span>This will go red when checked</span>
    </p>
    <input type="submit" value="Submit" />
  </form>
</body>
</html>

Click to view the demo

There is no specific selector for unchecked elements, but you can combine :checked with the negation selector.





















Home »
  HTML CSS »
    CSS »




CSS Introduction
CSS Background
CSS Border
CSS Box Layout
CSS Text
CSS Font
CSS Form
CSS List
CSS Selectors
CSS Others
CSS Table