0

I have to projects, basing on the same HTML and different CSS. I want to bring together the CSS definitions of those two projects in one Less file, with variables to define the differences.

Project 1:

.userbar {
    background: #fff;
}

Project 2:

.userbar {
    background:url(../images/bg-userbar.png) no-repeat 100% 100%;
}

The merged Less Code should be:

userbar {background: @bg_userbar}

Then I can define the color for project 1 like this:

@bg_userbar: #fff;

But for project 2, is this valid less code?

@bg_userbar: background:url(../images/bg-userbar.png) no-repeat 100% 100%;

Many thanks for your help! Sascha.

1
  • Wasn't aware of Less. Seems interesting. Like the sort of Variables, so-to-speak, that you can accomplish with Less. Commented Jan 5, 2013 at 18:18

2 Answers 2

4

the first variable definition is of course valid, for the second one you just need to escape it:

@bg_userbar: #fff;
@bg_userbar: ~"url(../images/bg-userbar.png) no-repeat 100% 100%";

.userbar {background: @bg_userbar}
Sign up to request clarification or add additional context in comments.

Comments

1

I just spent some time again with this issue.

@bg_userbar: url(../images/bg-userbar.png) no-repeat 100% 100%;
.userbar {
    background:@bg_userbar;
}

is valid less code and compiles to

.userbar {
  background: url(../images/bg-userbar.png) no-repeat 100% 100%;
}

But thanks for the hint with escaping; although it's not necessary.

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.