简体   繁体   中英

Is it possibile in css to link a background image based on a link that appears in the HTML of the page?

The page html has a link in it, that I want to use as the background image of the page. The problem is that there are hundreds pages all with different links in them and I want to use this stylesheet to affect them all. Possible?

Externally included CSS stylesheets have no way of getting information from any inputs or the DOM.

Here is a basic solution using jquery.

Assuming jquery and a selector on the element that contains the URL.

IE:

 <img src="path/to/image.jpg" id="backgroundImage"/>

JS:

$(document).on('load', function() {
    var imgSrc = $('#backgroundImage').prop('src');
    $(body).css('background', 'url(' + img + ')');
});

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