开发者

Is there a way to use CSS attribute as value?

I mean, is there a way to do something like开发者_高级运维:

width: 92%;
left: (100-width)/2;

so I can change the width without care with the "left"?

obs. I don't want to know about other ways of doing this centering, like with magins=auto, I just want to know if I can use an css attribute as a value to other attribute. Thanks! :)


Not in pure CSS, no.

CSS precompilers like LESS offer it, though.


Currently no, although, css calculations seem to allow for the possibility of this, albeit at a later date.

It might be worth reading this pre-existing question: Value calculation for CSS


There's no way unless you are generating the css itself dynamically, with this for instance

Also some browsers have some support for css variables, but you can't do math on them as AFAIK


As far as I know: No

EDIT:

You could do it from JavaScript using DOM like:

object.style.left = (100 - object.style.width) / 2

But, you would have to call this code, every now and then, and I don't think that's what you intended.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜