1
純粋なCSSによって、の中の擬似要素の要素のz-index
の値を表示したいとします。css変数の型をキャストする方法は?
これを達成するために、私はCSS変数を使用することに決めました。しかし、問題は、z-index
は数字ですが、content
は文字列です。どのように私は価値をキャストすることができますか?
p
がz-index: var(--z)
を使用する場合は、div
をz-index: 8
と表示しています。 p
はz-index
を使用し、同時にafter
を表示します。どうしたらいいですか?
p {
position: relative;
z-index: var(--z);
background: silver;
}
p:after {
content: var(--z);
color: red;
}
div {
background: red;
z-index: 8;
}
/* just some styling and positioning stuff bellow */
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">
I have correct z-index, but have no :after
</p>
<p style="--z: '9'">
I have no z-index, but have :after
</p>
<div></div>