简体   繁体   中英

Rendering CSS background-image

I have an image on server folder (C:\\resources\\image\\client-a.jpg). Is it possible to render the background-image in such a way that if client-a.jpg is available, then render it else render client-default.png?

    <style type="text/css">
    #divElement {
        position: absolute;
        top: 50%;
        left: 50%;
        margin-top: -200px;
        margin-left: -400px;
        background-image: url(/TestWeb/theme/client-default.png);
        width: 800px;
        height: 400px;
    }
</style>

You can use multiple images provided they are not transpareny like this

background-image: url(/image/client-a.jpg),url(/image/client-default.png);

So when the first is not available the second will be displayed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM