question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

background image using html inline styles is not working

See original GitHub issue

This a 🐛 bug report

I’m trying to use HTML inline styles to show a background image to a div. This is done inside HTML

code directly.

🎛 Configuration (package.json)

  "scripts": {
    "start": "parcel index.html"
  }

🤔 Expected Behavior

I expect images to work using the inline style background image even if the URL is local

😯 Current Behavior

the image does not appear and

When i open the URL of the image ‘localhost:1234/images/image.jpg’

it is like opening localhost:1234

This only happens when I use a local image, if I use an image URL, it works normally.

💁 Possible Solution

images works using the inline style background image even if the URL is local

🔦 Context

Im trying to use an image slider that fills the whole window. That is why i need to inline image background URLs inside HTML

💻 Code Sample

This does not work

<div class='bg' style="background: url('./images/april-2015.jpg') no-repeat center center fixed"></div>

This works

<div class='bg' style="background: url(http://news.images.itv.com/image/file/626702/img.jpg) no-repeat"></div>

🌍 Your Environment

Software Version(s)
Parcel latest
Node latest
npm latest
Mac

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
JeffreyRJohnsoncommented, Jan 19, 2018

a local background image won’t work with external css either .

7reactions
mohammadnazari110commented, Aug 30, 2018

<div class="img-banner" :style="{'background-image': 'url(' + require('./assets/media/baner1.jpg') + ')'}"></div>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inline CSS background-image not displaying - Stack Overflow
The developer view in my browser shows that the image and CSS file are linked correctly, but nothing is displaying. Any help greatly...
Read more >
How to fix CSS background-image not working | HTML/CSS
1. Check that your CSS file is linked correctly in your HTML file. · 2. Make sure the image path is set correctly...
Read more >
CSS Background Image Not Working - Position Is Everything
If the CSS file is not properly linked to the HTML file, the background would be white and not show any style or...
Read more >
background-image - CSS: Cascading Style Sheets | MDN
The background-image CSS property sets one or more background images on an element.
Read more >
CSS background-image property - W3Schools
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found