4

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! :)

4 Answers 4

6

Not in pure CSS, no.

CSS precompilers like LESS offer it, though.

Sign up to request clarification or add additional context in comments.

6 Comments

LESS looks incredible! It adds all the features CSS as a language misses so dearly! +1 for the reference :-)
+1 thanks! The doubt now is: can I use it with xul?
@Tom I'm not sure I understand? LESS is a pre-processor, you will have to run a small program on the style sheets before you can use them. The end result is normal CSS that should work everywhere
Ah, ok.. so, with this 2 lines of code from my example, saving a file as test.less and running it with command line less test.less it just opens, as if was vim editor opening the file.. I'm reading about how to it..
the docs talk about lessc, but I found just less with ubuntu's apt-get...
|
3

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

4 Comments

@Tom, yeah; I'm excited by the possibilities too! =)
Interesting! Hadn't heard of these. +1
@Pekka, don't they sound fun? =) I'm almost terrified at the prospect of dealing with the browser implementation, though... =/
yeah, they sound interesting! Although it will surely take a few years until we can even think about using them.
1

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

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.