3

Ive read through some of the other topics but i couldnt find a solution that worked. But someway the the url shows up as http:="" mysite.com="" wp-content="" uploads="" 2015="" 08="" matchups-1.png")

This is the code I'm using. How do I prevent it from adding the extra "" and spaces?

<div style="background-image: url("<?php echo $bgimage; ?>"); background-position:cover;"></div>

I've tried to code like this, but this didnt work:

<div style="background-image: url(\'<?php echo $bgimage; ?>\'); background-position:cover;"></div>

as some answers suggested but still I'm either doing something wrong or it doesn't work. Can anyone tell me a solution? thanks.

3 Answers 3

5

You can simply use

<div style="background-image: url('<?php echo $bgimage; ?>'); background-position:cover;"></div>

or

<div style="background-image: url(<?php echo $bgimage; ?>); background-position:cover;"></div>

quotes are not necessary in an url

Sign up to request clarification or add additional context in comments.

Comments

3

The problem is the double quote " character you use for url(). Just try without or with a single quote instead.

<div style="background-image: url(<?php echo $bgimage; ?>); background-position:cover;"></div>

Comments

2

you should solve it with 3 ways..

  1. put this in the

<style type="text/css">
    .logo {
    background: url(<?php echo $img_url; ?>);
    }
    </style>

  1. Or you can simply use the inline style attribute and define the background-image.

    <div style="background-image: url(<?php echo $img_url; ?>);">
    

  2. or With the use of JQuery

<input type="text" class="imgcntnt" />
    <script type="text/javascript">
        var input_image = $('input.imgcntnt').val();
        $('body').css('background', 'url(' + input_image + ')');
  </script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.