What I want to do is to use <p onclick='this.innerHTML++'>0</p>
and make this code have a black background that covers the whole screen and center the text in it. I want it to not have a body element or an html element as I just want the <p>
element.
I tried using box-shadows and the transform property in the style
attribute.
<p onclick='this.innerHTML++' style='color: white; width: 100vw; height: 100vh; transform: translate(-50vw, -50vh); box-shadow: 50vw 50vh black;'>0</p>
That just displayed a quarter of the viewport a fourth of whiteness which meant the box-shadow wasn't working. I found it added a margin, so I removed it. It still didn't work. It centered the text though. I know how to do it with 2 elements, but I want to keep the code with only the <p>
element.
This time I tried using the background property.
<p onclick='this.innerHTML++' style='color: white; width: 100vw; height: 100vh; background: black; text-align: center'>0</p>
This time the code did everything correctly except positioning the text vertically centered.
Is it possible to do this all in 1 element, center the text both horizontally and vertically, and display a black background that covers the whole screen?