Home > Article > Web Front-end > How can I create dynamic background images for a footer using SASS?
When styling a website's footer with multiple widgets, adding visual interest with unique background images can enhance the aesthetics. Using SASS, you can randomize the background image selection from a defined list.
SASS v3.3.0 introduced the random() function. By combining this with a list of image URLs and variable interpolation, it's possible to generate CSS that dynamically chooses a random background image during compilation.
$imgKey: random(5); $list: "url('http://domain.com/blablabla/apple.png'), url('http://domain.com/blablabla/banana.png'), url('http://domain.com/blablabla/cherry.png'), url('http://domain.com/blablabla/durian.png'), url('http://domain.com/blablabla/eggplant.png')"; $nth: nth($list, $imgKey); #footer-widgets .container .row { background-image: $nth; background-position: right bottom; background-repeat: no-repeat; }
Refer to the live example available at: http://sassmeister.com/gist/8966210.
Keep in mind that, as with any SASS compilation, the random image selection only occurs during SASS compilation, not necessarily during every page visit.
The above is the detailed content of How can I create dynamic background images for a footer using SASS?. For more information, please follow other related articles on the PHP Chinese website!