Add background image using php

Popy Sunny

I'm using wordpress and ACF plugins to add an image :

http://www.advancedcustomfields.com/resources/image/

I would like to add an image in a div as a background. I used this code in my style.css but it doesn't work :

background-image: url(<?php $image = get_field('image_projet');?> <img 

src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />);

Thanks for you help

Stéphane

A css file contains CSS. Just CSS. You can't write html or PHP into a CSS file. If you want to generate a CSS property with PHP, you must use the <style>...</style> tags directly in your PHP file (the view). For instance :

<?php $image = get_field('image_projet'); // fetch the ACF field ?>

<html>
    <head>
        <title>Page's Title</title>
        <style>
            .your-div {
                background-image: url('<?php echo $image; ?>');
            }
        </style>
    </head>
    <body>
        <!-- this div uses the $image URL as a background. -->
        <div class="your-div">
            Lorem Ipsum.
        </div>
    </body>
</html>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

using background-image with php

From Dev

using background-image with php

From Dev

set background image using php

From Dev

add background image to android ListView using Picasso

From Dev

Add background image to div using data uri

From Dev

Add background image using Javascript CSS property

From Dev

Add a pattern repeated image as a background of another image using ImageMagick convert

From Dev

PHP thumb resize png image but add black background

From Dev

Add a background Image for ImageButton

From Dev

How to add a background image

From Java

How to add background-image using ngStyle (angular2)?

From Dev

How do I add a background image and label to a UIBarButtonItem using Swift

From Dev

Add a custom background image as my uiwebview starts to load (using Swift)

From Dev

How to add a repeating png image in the background of a webpage using CSS?

From Dev

How to add a background image to a plot created using D3

From Dev

How to add background-image to AnchorPane by using Scene Builder in JavaFX?

From Dev

How to add background-image to AnchorPane by using Scene Builder in JavaFX?

From Dev

Add a custom background image as my uiwebview starts to load (using Swift)

From Dev

How to add a background image to a JFrame with no panels, without using a JLabel?

From Dev

How to add a background image to a plot created using D3

From Dev

How to add a background image using an absolute path in markup

From Dev

Add css background image in node.js using express

From Dev

Trimming extra white background from image using ImageMagick in PHP

From Dev

How to show an image in the background when using HTTP Basic Authentication with PHP

From Dev

How to show an image in the background when using HTTP Basic Authentication with PHP

From Dev

using an image as a background in java

From Dev

Using background image in rails

From Dev

Using a background image CSS

From Dev

Php GD add text to png image always follow image background color

Related Related

  1. 1

    using background-image with php

  2. 2

    using background-image with php

  3. 3

    set background image using php

  4. 4

    add background image to android ListView using Picasso

  5. 5

    Add background image to div using data uri

  6. 6

    Add background image using Javascript CSS property

  7. 7

    Add a pattern repeated image as a background of another image using ImageMagick convert

  8. 8

    PHP thumb resize png image but add black background

  9. 9

    Add a background Image for ImageButton

  10. 10

    How to add a background image

  11. 11

    How to add background-image using ngStyle (angular2)?

  12. 12

    How do I add a background image and label to a UIBarButtonItem using Swift

  13. 13

    Add a custom background image as my uiwebview starts to load (using Swift)

  14. 14

    How to add a repeating png image in the background of a webpage using CSS?

  15. 15

    How to add a background image to a plot created using D3

  16. 16

    How to add background-image to AnchorPane by using Scene Builder in JavaFX?

  17. 17

    How to add background-image to AnchorPane by using Scene Builder in JavaFX?

  18. 18

    Add a custom background image as my uiwebview starts to load (using Swift)

  19. 19

    How to add a background image to a JFrame with no panels, without using a JLabel?

  20. 20

    How to add a background image to a plot created using D3

  21. 21

    How to add a background image using an absolute path in markup

  22. 22

    Add css background image in node.js using express

  23. 23

    Trimming extra white background from image using ImageMagick in PHP

  24. 24

    How to show an image in the background when using HTTP Basic Authentication with PHP

  25. 25

    How to show an image in the background when using HTTP Basic Authentication with PHP

  26. 26

    using an image as a background in java

  27. 27

    Using background image in rails

  28. 28

    Using a background image CSS

  29. 29

    Php GD add text to png image always follow image background color

HotTag

Archive