Vue: Allow css variable in style binding (object syntax)

Created on 23 Oct 2016  Â·  7Comments  Â·  Source: vuejs/vue

I am not sure if this is intentional, I would like to be able to do:

<div :style="{ '--color': player.color }">…</div>

instead of:

<div :style="'--color :' + player.color">…</div>

I was able to find the workaround quickly thanks to the doc search here: http://vuejs.org/guide/migration.html#v-bind-style-with-Object-Syntax-and-important-deprecated

It's a bit different from !important so I would like to push for this feature.

Thanks a lot for your good work, I can work on a PR if you agree with this proposition.

improvement

Most helpful comment

@defcc --color is a CSS3 variable syntax.

All 7 comments

--color ? this is not a valid css property name

For object style binding, you could take a look at http://vuejs.org/guide/class-and-style.html#Object-Syntax-1, and the key should be a valid css property name.

@defcc --color is a CSS3 variable syntax.

I'm not sure if this should be supported – the current style binding only supports CSS properties AFAIK. Reopening this, however, so that @yyx990803 and other members can chime in with their ideas.

My mistake, haven't used it before, I'll google it :)

@phanan I believe the correct syntax is var(--color) and it's css4 not 3.

AFAIK var(--color) is the usage, --color: #fff is the definition syntax. I'm not sure about 4vs3, but it shouldn't affect our main issue here anyway.

Fixed in 4b8eb75

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hiendv picture hiendv  Â·  3Comments

franciscolourenco picture franciscolourenco  Â·  3Comments

robertleeplummerjr picture robertleeplummerjr  Â·  3Comments

seemsindie picture seemsindie  Â·  3Comments

loki0609 picture loki0609  Â·  3Comments