0

Is it possible to declare your self a variable in CSS, for example if i had the same property for the following two tags

.cellLeft{
width: 45%;
min-height: 130px;

}
.cellRight{
width: 45%;
min-height: 130px;
}

Is it possible to declare x=130px so i dont have to keep changing min-height everywhere like for example;

x=130px;
.cellLeft{
width: 45%;
min-height: x;

}
.cellRight{
width: 45%;
min-height: x;
}
1

1 Answer 1

3

You have to use a CSS preprocessor for this, like LESS or SASS. You can't do it with pure css. Have a look here: http://lesscss.org/ or here: http://sass-lang.com/ (I use LESS myself)

Extra:

A CSS-only solution to your example would be to use a modular approach in which you define multiple classes for specific attributes which you can re-use in your HTML. I would suggest doing this even when using a CSS preprocessor. So for your example you could make these classes:

.cell {
    width: 45%;
    min-height: 130px;
}
.cell-left {
}
.cell-right {
}

And then add both the cell and the cell-left / cell-right classes to your HTML elements. This way you only have to declare the width and min-height properties once.

Or, you could do:

.cell-left, .cell-right {
    width: 45%;
    min-height: 130px;
}

So you only have to change it once as well.

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

1 Comment

thanks alot Leon. that worked perfectly for my example!

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.