require image in CSS
See original GitHub issueIn header.jsx, we can require a image like,
<img className="Header-brandImg" src={require('./logo-small.png')} />
Is it possible to require a image in CSS? Something like:
.HomePage-container H1:before {
content: url({require('/images/test.png')});
}
<bountysource-plugin>
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How to use images in css with Webpack - Stack Overflow
Webpack outputs to a dist folder, but I can't figure out how to get images there. Here is my webpack setup: var path...
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 background-image CSS property sets one or more background images on an element.
Read more >Images in CSS (file-loader) - SymfonyCasts
When we tell Webpack to load a CSS file, it actually parses the background images and - basically - requires them! It does...
Read more >background-image | CSS-Tricks
The background-image property in CSS applies a graphic (e.g. PNG, SVG, JPG, GIF, WEBP) or gradient to the background of an element.
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 FreeTop 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
Top GitHub Comments
I find out the solution: just use the relative path so that webpack will resolve the path:
Use this:
Don’t use this
Let me clarify the question:
Since my images will be deployed in CDN, I set the config in webpack.config.js like
All my images are located at public/images, so I need ‘require’ method to add domain name for the images. It’s easy to require a image in JSX, like
Then it will be compiled to
But I can’t figure out how to require a image in CSS. I need something like this: