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
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.
Comments