I am trying to set my featured image as a background image in CSS.
I need to show the same featured image in two places in the HTML and CSS.
How do you use the_post_thumbnail()
in CSS?
HTML
<div class="magnify">
<div class="large"></div>
<img class="small" <?php the_post_thumbnail( 'large', array
('class' =>'img- responsive') ); ?> />
</div>
CSS
.large {background: url('img/image.jpg') no-repeat;}
As Tim Malone stated in the comments, you will need to do this with inline styles. You can do something like this:
Note that I am using
wp_get_attachment_image_src
so that I can get the image dimensions in case I need them. In this case, it is to set the height of the div to the height of the image.