Skip to content

Instantly share code, notes, and snippets.

@JoelBesada
Created March 19, 2012 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoelBesada/2086514 to your computer and use it in GitHub Desktop.
Save JoelBesada/2086514 to your computer and use it in GitHub Desktop.
Basic CSS States
/* Basic CSS States */
body {
padding: 100px;
}
/* When a button is pressed, overwrite the transition property
to remove the delay, so that we can instantly change the color */
.red:active ~ p.perm, .green:active ~ p.perm, .blue:active ~ p.perm {
transition: color 0;
}
.red:active ~ p {
color: red;
}
.green:active ~ p {
color: green;
}
.blue:active ~ p {
color: blue;
}
/* The large delay prevents the color from returning to its default
state after we've changed it with the buttons. */
p.perm {
transition: color 0 9999999s;
}
<button class="red">Red</button>
<button class="green">Green</button>
<button class="blue">Blue</button>
<p class="temp">
This text will only have the color while the button is pressed down.
</p>
<p class="perm">
This text will keep the given color even after the button is released.
<p>
{"view":"split-vertical","seethrough":"","prefixfree":"1","page":"css"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment