0

I don't understand why selecting form will apply the active class to the label:

form :active {
  color: red;
}


form button {
  background: white;
}
    <form>
      <label for="my-button">My button: </label>
      <button id="my-button" type="button">Try Clicking Me or My Label!</button>
    </form>
Maarti
  • 3,014
  • 4
  • 14
  • 31

1 Answers1

0

"The :active selector is used to select and style the active link. A link becomes active when you click on it."

With this:

form:active {
  color: red;
}

you set the color of form and all the elements inside to red when active (when you click anywhere on your form)

Iulius
  • 628
  • 4
  • 13
  • Thank you. So if I assign a CSS selector to the parent, it will always, unless otherwise stated, affect the children? –  Oct 23 '18 at 18:52
  • 1
    note the *space* in the selector of his code which is important – Temani Afif Oct 23 '18 at 18:59