<body> css | SoloLearn: Learn to code for FREE!


<body> css

How to make that when you click on a div, the body changes color to the desired one!

8/16/2018 10:02:13 AM


9 Answers

New Answer


If this is what you want. Hope it helps☺️☺️. https://code.sololearn.com/WKeo3k7kQdPO/?ref=app


thanks all)



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!


HTML: <div onclick="bodyBgColor()"></div> JS: function bodyBgColor() { document.body.style.backgroundColor = "#cccccc"; }


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 *\ }