Unocss works well with background images in test environments, but does not display them properly when packed into production
See original GitHub issue一、普通写法
<div bg="center no-repeat" class="bg-[url(./src/assets/uploads/bg.png)]"></div>
二、配置写法
<!-- <div soumns-min soumns-bg-bg-png>777</div> -->
rules:[
[
'soumns-min',
{
'min-width': '100vw',
'min-height': '100vh',
'box-sizing': 'border-box'
}
],
// 动态背景
[
/^soumns-bg-(.*)$/,
([_, d]) => {
let img = d.split('-')[0]
let type = d.split('-')[1]
return {
background: `url('./src/assets/uploads/${img}.${type}')`,
'background-size': '100% 100%',
'background-repeat': 'no-repeat',
'box-sizing': 'border-box'
}
}
]
]
Issue Analytics
- State:
- Created a year ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How to fix CSS background-image not working | HTML/CSS
To help with that, here are four ways to fix your background-image not working, using HTML and CSS: 1. Check that your CSS...
Read more >Background image not showing in Safari - Stack Overflow
Safari has an apparent bug where it won't show some jpg/JPEG images of a certain type in backgrounds if some criteria are met....
Read more >How to Use Background Effects in Microsoft Teams Meetings
Microsoft Teams meetings support the use of background effects like blurring or background images (custom or a default set from Microsoft).
Read more >WordPress Background Images: How to Add, Edit ... - Kinsta
Learn how to activate, edit, and customize them in this in-depth guide. ... The background image may not be shown in its entirety...
Read more >SVG in CSS - Iconify Documentation
Mask image, combined with background color set to currentColor. First 2 methods can be ... Icons with palette (hover does not change icon...
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
This issue is probably not related to unocss. You probably want to read up on https://vitejs.dev/guide/assets.html#the-public-directory
Basically, vite does not bundle your images because they are in your src folder. It isn’t aware of them. You want them in the public folder instead (or the static folder like in frameworks like svelte-kit and nuxt).
I created a simple plugin to handle this requirement. vite-plugin-unocss-bgimg