/    Sign up×
Community /Pin to ProfileBookmark

Can I have variables i CSS?

Can I have variables?
Like boxlenghth=30

I can then use this in different classes for different things.
Then… I can make one change and effect xx instances where I have used?

Not a problem for me if only available in latest browsers.

But… is something like this available?

Thanks

OM

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@EmondoFeb 14.2016 — Although this is possible, I really don't recommend it.

Majority of the browsers do not support this. Only the latest version of Google Chrome, Firefox, and Safari support this.

However, if are still wanting to do this:

.element {

--somerandomvar: red;

}

html, body {

background-color: var(--somerandomvar);

}
Copy linkTweet thisAlerts:
@OM2authorFeb 14.2016 — @Kevin2 thanks for the reply.

i tried what is suggested in the link.

not having luck.

this is what i have:

[CODE]:root
{ --topLocationOne: 2cm;

}

#div1

{ top: var(--topLocationOne);

}[/CODE]

What am I doing wrong?

The syntax and usage of variables seems so odd?

Why couldn't they make simpler?

EDIT: i read up a few other things on the net.

i saw this in a few places "Chrome 49 is getting full support for CSS variables so developers will able to ..."

i checked my upto date latest version (or i thought it was!) and i have: Version 48.0.2564.109 m

am i missing out on all the fun?
×

Success!

Help @OM2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...