Job listings with filtering with React and Tailwind
Design comparison
Solution retrospective
The most difficult part of this project was related to deployment and how the assets files were organized in the build process. I managed to get the job images right but still can't figure out the background of the top.
What specific areas of your project would you like help with?If someone could tell me what I did wrong that is making the top background not appear on the screen, I would appreciate it. It's probably something related to the paths.
Community feedback
- @markuslewinPosted 6 months ago
Hiya, 1 solution for each approach you're trying:
_ - _ - _ - _
If you want to apply the image using the
style
prop, you have to add"
s to the string, as mentioned in https://vitejs.dev/guide/assets.html#importing-asset-as-url.When passing a URL of SVG to a manually constructed
url()
by JS, the variable should be wrapped within double quotes.Like this:
const style = { backgroundImage: `url("${bgHeader}")`, };
_ - _ - _ - _
If you want to apply the image using Tailwind classes, you have to specify the URL relative to your CSS file (
index.css
).// tailwind.config.js export default { theme: { extend: { backgroundImage: { "desktop-header": "url('../assets/bg-header-desktop.svg')", }, }, }, };
// Background.jsx export default function Background() { return <div className="w-full h-[155px] bg-desktop-header bg-center"></div>; }
What's currently happening is that Tailwind injects the URL
url('./src/assets/bg-header-desktop.svg')
into the CSS file. When Vite checks the CSS file, it tries - and fails - to find the SVG file atsrc/css/src/assets/bg-header-desktop.svg
.Marked as helpful2@GustavoSouza123Posted 6 months ago@markuslewin this was really helpful. Thanks a lot.
1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord