<body> css | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 3

<body> css

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

16th Aug 2018, 10:02 AM
oTARANo
oTARANo - avatar
8 Respuestas
+ 9
If this is what you want. Hope it helps‚ėļÔłŹ‚ėļÔłŹ. https://code.sololearn.com/WKeo3k7kQdPO/?ref=app
16th Aug 2018, 10:13 AM
Meet Mehta
Meet Mehta - avatar
+ 5
thanks all)
16th Aug 2018, 4:35 PM
oTARANo
oTARANo - avatar
+ 4
:)
16th Aug 2018, 4:37 PM
Meet Mehta
Meet Mehta - avatar
+ 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!
16th Aug 2018, 12:12 PM
Benneth Yankey
Benneth Yankey - avatar
+ 3
HTML: <div onclick="bodyBgColor()"></div> JS: function bodyBgColor() { document.body.style.backgroundColor = "#cccccc"; }
17th Aug 2018, 10:55 AM
–≠–Ľ—Ć–ľ–į–ī–ī–ł–Ĺ
+ 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 *\ }
16th Aug 2018, 4:12 PM
shashuri Magrease
shashuri Magrease - avatar
16th Aug 2018, 4:49 PM
oTARANo
oTARANo - avatar
+ 1
Good!
16th Sep 2018, 1:26 PM
Dmitriy Yakovlev
Dmitriy Yakovlev - avatar