Support

Account

Home Forums General Issues What would the code be to use an image field as a 'background-image' for a div?

Solved

What would the code be to use an image field as a 'background-image' for a div?

  • What would the code be to use an image field as a ‘background-image’ for a div?

    I looked in the forum for an answer to this, but did not find one.

    Thanks for your help.

  • What is the return value for the field set to? If it is URL then

    
    <div style="background-image: url(<?php the_field('image_field_name'); ?>);">
    
  • That did it!

    This was really important to my project and I really appreciate your help.

    Thank you so much!

  • I was wondering if there was a way to use this with ID to utilize the responsive image serving integrated in WP Core (maybe its not possible). TLDR looking to insert background-image inline on a Feature Header section that doesn’t make mobile users download the full size image used on desktop browsers. Thanks in advance for any help!

  • You would have to build it yourself, getting the different sized images and they include an inline style block

    
    <style>
      .....
    </style>
    

    with all of the responsive/screen size css that you’d normally use.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘What would the code be to use an image field as a 'background-image' for a div?’ is closed to new replies.