Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

any way to combine background-size classes?

any way to combine background-size classes?

Problem

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?

Problem courtesy of: Chris Tolworthy

Solution

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

element.style.backgroundPosition = value1 + '% ' + value2 + '%';
Solution courtesy of: Alex

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

any way to combine background-size classes?

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×