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

+3

<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

oTARANo

9 Answers

New Answer

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

+2

https://code.sololearn.com/W16pFRueh73e/?ref=app

+1