I know that it is possible to make multiple background layers with CSS, but can I layer multiple backgrounds coming from different classes?
Say I had divs acting as tiles that could have mountains or hills and could belong to a certain country.
.mountain {
background: url("mountain.png");
}
.hill {
background: url("hill.png");
}
.bluecountry {
background: url("bluecountry.png");
}
.redcountry {
background: url("redcountry.png");
}
.greencountry {
background: url("greencountry.png");
}
would be my css. However, this doesn’t work; when I do something like
<div class="hill bluecountry">
it will not layer the backgrounds, and will only use one of them.
Is there any way to make this work? I actually have more stuff than this, and it would be a huge waste of time to have to individually write CSS multiple backgrounds for every possible combination.
There’s no way to merge the
backgroundattribute using multiple classes — it can only be set once. What you could do is:position: relative)position: absolute)top: 0px; left: 0px;, and withbackground-position.Here’s an example of what I mean:
HTML
CSS
http://jsfiddle.net/chriskorosu/z269x0oc/1/