Chris Tolworthy
Chris Tolworthy

Reputation: 2096

any way to combine background-size classes?

I'm trying to change background-size using css: I want 100 heights and 100 widths, but do not want to create 10,000 classes. e.g.

// style
.tall {background-size: whatever 200%}
.narrow {background-size: 50% existing}
// javascript
element.className ="tall narrow";

As car as I can tell, I need to specify every possible value, e.g.

.tall1 {background-size: 1% 200%}
.tall2 {background-size: 2% 200%}
.tall3 {background-size: 3% 200%} // etc.

Is there any way round this?

Upvotes: 0

Views: 107

Answers (1)

Alex
Alex

Reputation: 9471

If you're using Javascript, you could dynamically set the values.

element.style.backgroundPosition = value1 + '% ' + value2 + '%';

Upvotes: 2

Related Questions