0

I think it's a easy question, but i found nothing in google which helps me.

I've the following code:

-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;

Now i use it in more than 1 CSS class. And when i want to change the box-sizing, i don't want to change it in all statements. So i want to use some CSS variable. But i don't find a example to define more than one statement in a CSS variable. Any solution?

What i've already tried:

@boxsizing: 
(
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
)
4
  • 2
    CSS and variables? There are no variables, constants or any other place-holding mechanisms in CSS. However, you can use the same rules on many selectors by grouping them with the comma-separator ,. Commented Nov 12, 2012 at 12:04
  • CSS don't support variables. See stackoverflow.com/questions/7247202/… Commented Nov 12, 2012 at 12:05
  • It depends the statement, you should be more specific. In CSS it's called media queries: w3.org/TR/css3-mediaqueries Commented Nov 12, 2012 at 12:05
  • Saw some code with variables. But now i know it was developed with LESS or something. Sorry for this stupid question :) Commented Nov 12, 2012 at 12:12

3 Answers 3

3

Vanilla CSS does not use variables in the way you intend them to use.

For such behavior you need other tools to generate (valid) CSS out of dynamic code files. Examples include the following:

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

1 Comment

Ah! Also heard about LESS. But never read an article about it! Thank you! +1 &, when i can, accepted.
2

CSS has no such thing as variables. You can make your code more DRY by defining the same styles for several selectors, for instance:

.boxsizing, #my_element, div, a.foobar {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

1 Comment

Also tried. But anything doesn't work. So i want to start to develop with variables.
0

You need something like SCSS to do that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.