+ 3
<body> css
How to make that when you click on a div, the body changes color to the desired one!
8 Respostas
+ 9
If this is what you want.
Hope it helps☺️☺️.
https://code.sololearn.com/WKeo3k7kQdPO/?ref=app
+ 5
thanks all)
+ 4
:)
+ 3
The above code works, but only if you tap on the text or div block. This is because the div height is equal to its content. To make it flexible so you tap anywhere on the body to change color, you will need to expand the size of the div equal to the view port (backdrop).
add these styles to the div element or you could create a class and assign to the div, either way works
style = "width: 100vw; height: 100vh; z-index: 1000"
Hope it helps, happy coding!
+ 3
HTML: <div onclick="bodyBgColor()"></div>
JS: function bodyBgColor() {
document.body.style.backgroundColor = "#cccccc";
}
+ 2
Well that will be easier if you make the entite body section a link.
Then use the pseudo class of link
a:active {
\*your style fors here *\
}
+ 1
Good!