sayyesdoit
sayyesdoit

Reputation: 41

Please inform me how to use variables as the attribute value in CSS

I'm using PUG.

I entered 10 on the variable h.

I'd like to use the h as a property of element named item.

- var h=10
doctype html
html
    head
        style.
            .item {height: hpx;}
    body
        .item Hello!

Of course it didn't work.T.T

How can I make it work?

Upvotes: 0

Views: 180

Answers (2)

Nenc
Nenc

Reputation: 21

You can also use below code :

In HTML file:

html
 head
    style.
        .item { height: var(--h);color: var(--color); }

 body
    .item Hello!

In CSS file:

:root {
  --h: 10px;
  --color: red; 
}

Hope it's work well for you.

Thanks.

Upvotes: 1

dNitro
dNitro

Reputation: 5345

Use String Interpolation:

- var h=10
doctype html
html
    head
        style.
            .item {height: #{h}px;}
    body
        .item Hello!

Upvotes: 1

Related Questions