Sass mixin to have multiple theme based background images

Let’s say you want to have themed background images on your website aswell as a different one depending on wether it is day or night.

Sure you could achieve this with javascript and just replace the background image. But this time I wanted to to this only via css.

These are the images we want.

hero_spring_light.jpg
hero_spring_dark.jpg
hero_autumn_light.jpg
hero_autumn_light.jpg

If we wanted to do this in CSS we have classes for each season and another one for the themes (light and dark). But what happens if we add another theme? Or whe change the filetype of the photos?

Then we would have to change a lot of code.

This mixin saves us:

In the code we simply reference it like this and include another image for every class we have. The season gets included automatically for every class and we simply have to specify the theme we want.

The theme is just an idea. I used it to have different photos with text on it in different languages.

--

--

With a focus on possibilities I want to inspire you for new ideas, people and adventures, because I believe that there is a little artist in everyone.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Thimo Pedersen

With a focus on possibilities I want to inspire you for new ideas, people and adventures, because I believe that there is a little artist in everyone.