How can I show my image in this situation?
Here is my code:
<div class="clinic-logo" style="background-image: url( <?= base_url() ?>asset/dist/css/img/mylogo.gif )"></div>
When I saw it in inspect element it gives me this:
background-image: url( http://localhost/clinic/asset/dist/css/img/mylogo.gif );
Why does it say 'could not load image'?
Try this..
<div class="clinic-logo" style="background-image: url('<?php echo base_url();?>asset/dist/css/img/mylogo.gif')"></div>
Don't forget to load url helper in application/config/autoload.php.
should do the trick
<div class="clinic-logo" style="background-image: url("<?php echo base_url('asset/dist/css/img/mylogo.gif');?>")"></div>
anything passed into base_url() will be appended
<div class"container">
<img src="<? = base_url('Your image path')?>">
</div>
Related
On a Wordpress theme site I have this code:
<div class="gallery-img" style="background-image: url(<?php echo esc_url($image['sizes']['thumbnail']); ?>);">
However I need the background image url to be in ''.
So it works like this:
<div class="gallery-img" style="background-image: url('<?php echo esc_url($image['sizes']['thumbnail']); ?>');">
With it like that the PHP then does not work, how can I do the above so it works and so it has the '' around it?
How about inverting your single and double quotes ?
<div class="gallery-img" style='background-image: url("<?php echo esc_url($image['sizes']['thumbnail']); ?>");'>
I'm using this code.
<div class="bg-img1 size-a-3 how1 pos-relative" style="background-image: url();">
At this time how to get the post thumbnail url in background image?
The code should be like following,
<div class="bg-img1 size-a-3 how1 pos-relative" style="background-image: url(<?php the_post_thumbnail_url(); ?>);">
And if you want to get post thumbnail from a specific post/page using post ID it will be like following,
<div class="bg-img1 size-a-3 how1 pos-relative" style="background-image: url(<?php echo get_the_post_thumbnail_url($post_id); ?>);">
I know I'm probably missing something really obvious, but the background image isn't pulling through...
<div style='background-image: url(<?php echo $blogImage; ?>");'>
I've also tried:
<div <?php echo "style='background-image: url($blogImage);'";?> >
Syntax error
Use this
<div style="background-image: url('<?php echo $blogImage; ?>');">
Hope this helps
You have a missing " before the php opening tag. try to add it and check.
<div style='background-image: url("<?php echo $blogImage; ?>");'>
I have initialize a variable to fetch from this directory as shown
<?php $imgSrc = base_url()."decoy/thumbs/".$item["filename"]; ?>
now I want to assign the variable to a background url of css code block as shown but it is not displaying the image background
<div style="background: url('<?php echo $imgSrc ?>') no-repeat;" class="large"></div>
can anyone kindly assist me on how I can I achieve the above.
Follow these easy steps to investigate your problem.
After getting the image
<?php $imgSrc = base_url()."decoy/thumbs/".$item["filename"]; ?>
Verify what was returned to the image variable <?php echo $imgSrc; ?>
That way you will be better placed if you find nothing wrong update your question with the necessary information.
Finally I prefer you use string concatenation instead change this
<div style="background: url('<?php echo $imgSrc ?>') no-repeat;" class="large"></div>
to
<?php
$imgSrc = base_url()."decoy/thumbs/".$item["filename"];
echo '<div style="background:'.url($imgSrc).' no-repeat;" class="large"></div>';
?>
You need to put the "imagePath" in place of "imgSrc" so that the image will prompt in backgroud, because in the backroud-url there is no need of absoulte path only relative path will be ok for this.
$imgPath = "../decoy/thumbs/".$item["filename"]";
<div style="background: url('<?php echo $imgPath; ?>') no-repeat;" class="large"></div>
I am trying to set an image uploaded through custom fields plugin and have it display as the background of a div (which is used in a slider).
However the image is not displaying...I have text in the custom fields and that is showing okay so I think its something to do with the line of code I am using to pull in the image.
I am trying to set the background of .slide1 with the image.
The custom field name is slide1_background.
HTML:
<div class="slide1" style="background-image:url('<?php the_field('slide_bg1'); ?>');">
<div class="slide1-cont"><p class="slide-text">
<h1><?php the_field('slide_title1'); ?></h1>
<img src="<?php bloginfo('template_directory')?>/images/line.png" /></p>
<p><?php the_field('slide_content1'); ?></p></div>
</div>
CSS:
.slide1{
background-repeat:no-repeat;
background-size:cover;
background-position:center;
height: 800px;
}
Look at the difference in your code in your question, where you try to set the background-image, compared to the code in your comment in another answer where you're setting it as an image source.
the_field('slide_bg1') returns an array, so you're trying to set the background image source as a PHP array which gets converted to a string as "Array" so in your HTML it'll look like: background-image:url('Array')
You need to get the field first, then echo the url element of the returned array as the source of the background image:
$image = get_field( 'slide_bg1' );
if ( !empty( $image ) ) { ?>
<div class="slide1" style="background-image:url('<?php echo $image['url']; ?>');">
<?php }
Use echo
<div class="slide1" style="background-image:url('<?php echo the_field('slide_bg1'); ?>');">