I'm a beginner to css and js. But I have a basic question I can't find an answer for on google: can I change a background color on a div on click without using javascript and jquery, just with css?
Yes that's possible with the :targetselector and ids.
https://developer.mozilla.org/en-US/docs/Using_the_:target_selector
HTML:
<div id="demo">Demo</div>
<a href="#demo">Click me</a>
CSS:
:target {
background: green;
}
Demo: http://jsfiddle.net/Qptjq/2/
Or even cooler: http://jsfiddle.net/Qptjq/3/
:target requires IE9+ http://caniuse.com/#search=%3Atarget
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With