Referencing images from css
See original GitHub issueNoob question again: How do I reference images in my css? I’m doing this (the image is next to the css file in the folder):
.poster {
background: url(./hero-banner.jpg) no-repeat;
background-size: cover
}
The outputted css is:
._33hlffvz0sgxpxLxtaBGAu {
background: url(/b1e8ba2d0f312bdf6d0011f87d91bed1.jpg) no-repeat;
background-size: cover;
}
The image dosen’t show up (and I can’t open it in a new tab, for instance).
If I do this:
.poster {
background: url(/hero-banner.jpg) no-repeat;
background-size: cover
}
The outputted css is:
._33hlffvz0sgxpxLxtaBGAu {
background: url(/hero-banner.jpg) no-repeat;
background-size: cover;
}
But the image still dosen’t show, and if I try to open the image in a new tab, this is the url I get: chrome-devtools://devtools/hero-banner.jpg
Sorry for my stupid questions, but any help is much appreciated!
Issue Analytics
- State:
- Created 8 years ago
- Comments:17 (6 by maintainers)
Top Results From Across the Web
CSS Styling Images - W3Schools
CSS Styling Images · Rounded Images · Thumbnail Images · Responsive Images · Center an Image · Polaroid Images / Cards · Transparent...
Read more >How to reference an image from computer directory as a ...
Create a folder called, say, - "myWebsite" · Inside 'myWebsite' folder put all your html files · Inside 'myWebsite' folder create another folder ......
Read more >How to Add an Image to a CSS File
1. Open your website's stylesheet with your HTML editor or a text editor. · 2. Paste the following code into the sheet to...
Read more >background-image - CSS: Cascading Style Sheets | MDN
The borders of the element are then drawn on top of them, and the background-color is drawn beneath them. How the images are...
Read more >How do I reference images through CSS in a library ... - Drupal
Hi. I have created a module, added a library, added CSS and JS. The CSS and JS load correctly. However the images referenced...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I just faced the same issue, which only happened in dev mode - the images did show up after build.
Here are the steps that should help getting over it (inspired by https://github.com/webpack/style-loader/pull/96#issuecomment-228370602):
Create
internals/dev-preamble.js:Open
internals/webpack/webpack.dev.babel.jsand add one line:Here is what changes when you look at your CSS in Chrome’s inspector:
Might be worth doing this right in the boilerplate, but I’m not sure if my solution is elegant enough for a PR. Hope others spend less time making this work!
@mxstbr Has any solution been adopted for this issue? Except @kachkaev’s solution posted above? I am working on a project which has v3.0.0 as dependency.