[英]TailwindCSS - background image not loading on build
I'm doing a Frontend Mentor challenge and I've ran into a problem when publishing my project to Vercel.我正在做一个前端导师挑战,我在将我的项目发布到 Vercel 时遇到了问题。
The background image can't load.无法加载背景图像。 Everything works on my local machine, but when deployed, the only image that doesn't load is that background image.一切都在我的本地机器上运行,但在部署时,唯一不加载的图像是背景图像。
If anyone knows what I'm doing wrong, I'd be really happy to know.如果有人知道我做错了什么,我会很高兴知道。
//tailwind.config.cjs
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
theme: {
extend: {
colors: {
"huddle-violet": "hsl(257, 40%, 49%)",
"huddle-magenta": "hsl(300, 69%, 71%)",
},
backgroundImage: {
"desktop": "url('./images/bg-desktop.svg')",
"mobile": "url('./images/bg-mobile.svg')"
},
},
},
plugins: [require('prettier-plugin-tailwindcss')],
};
//index.html
<body class="bg-huddle-violet bg-mobile bg-contain bg-no-repeat">
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
The relative path being used is wrong.使用的相对路径是错误的。
./
with this you mean one heirarchy up. ./
有了这个,你的意思是一个层次结构。
But according to your question ./public/images/bg-mobile.svg
但是根据你的问题./public/images/bg-mobile.svg
So try replacing ./
with /
it should work.因此,请尝试将./
替换为/
它应该可以工作。
Final code:最终代码:
backgroundImage: {
"desktop": "url('/images/bg-desktop.svg')",
"mobile": "url('/images/bg-mobile.svg')"
},
backgroundImage: { "desktop": "url('/images/bg-desktop.svg')", "mobile": "url('/images/bg-mobile.svg')" },
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.