I want on pure css to show the value of z-index and the element in its pseudo-element.
I decided to use a css variable for this ( support by browsers ). But the problem is that for z-index there must be a number in it, and for content - a string. How to type?
In the following example, in the case when the z-index triggered, the silver p shown over the red div a. If content triggered, then a number is displayed at the end of the paragraph. How to make, that simultaneously worked both z-index , and content ?
p { position: relative; z-index: var(--z); background: silver; } p:after { content: var(--z); color: red; } div { background: red; z-index: 8; } /* дополнительная стилизация и размеры */ body { margin: 0; } p { margin: 1em .5em; padding: 0 .5em 0 3.5em; line-height: 2em; } div { position: absolute; top: .5em; left: 1em; height: 6em; width: 2em; } <p style="--z: 9"> У меня правильный z-index, но нет :after </p> <p style="--z: '9'"> У меня нет z-index, но есть :after </p> <div></div>