Home > Web Front-end > CSS Tutorial > How can I create dynamic background images for a footer using SASS?

How can I create dynamic background images for a footer using SASS?

DDD
Release: 2024-11-18 21:50:02
Original
976 people have browsed it

How can I create dynamic background images for a footer using SASS?

Dynamic Background Images with 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.

Solution Using SASS's Random Function

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;
}
Copy after login

Live Example

Refer to the live example available at: http://sassmeister.com/gist/8966210.

Important Note

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template