+ 9
just by using css and html is it possible to write a code that when we click an element its class changes to our wished class?
i mean change in attribute values just by using css
5 ответов
+ 8
Using CSS target selector, it's possible to add any class to the clicked element.
Set the element with and href attribute to an id that points to itself. eg.
<a href="#self" id="self">Click here to change border and background color</a>
Set your wish class as:
.wish, :target { /* wish class */
border: 1px solid steelblue;
background-color: beige;
}
Check out the sample here
https://code.sololearn.com/Wa5ScJFX1IEE/?ref=app
+ 3
When it comes to values, it depends on the specific situation. The value itself wouldn't change, but it may be possible to trigger the use of a different set of values when the user clicks.
On-the-fly class changing requires JavaScript.
+ 1
No CSS is used for styling the document and for basic logic (e.g. :hover). You would have to use JS to achive such effect.
- 5
3
- 6
3