I’m trying to add a background image to my 404 page. I’ve pasted the code into the 404 liquid file, using the image URL from my settings files folder, but it’s not working. The webpage is displaying my code, and no image (should locate below the error text I created). Can anyone help me get the code right? Here’s the snippet I wrote:
oh wow – there is a lot of mix up going on here … first off, what element should be the one displaying that background? I assume for the sake of ease, that it’s the html page itself, i.e. I use the body element as the selector. If you want another element, replace that selector with the appropriate one:
fantastic when I had my image on the whole page ahahahah!
Anyway, yea sorry for my “mix”, trying to learn and am very passionate about coding. Ok my body is not the whole page but should be below the heading 4 and the “continue to shopping” bar. So how do I define this portion?
Thank you very much for help and your fast response
thank you again for your interest.
I tried to follow your instructions and tried to wander into the web to learn more about css. You told to define my selector which I didn’t want to be the whole body but just a portion. Eventually, I came up with this sheet and actually managed to obtain what I wanted. Hope this could help other users.
While I was choosing the path for my jpg file, I wrote my Desktop/img.jpg path, because the directory is Desktop, but my store didn’t display the image, while it worked using the url from Settings>File. Where’s the mistake?
Also, would you please show me how to set the css in order to have a responsive image, automatically resizing on mobile too?
Look forward for your answer and again thank you very much for your support.
Thank You for Your Response
solved by js:
look at it and please tell me Is this the standard method?
if (document.title.match(“404 Not Found”)){
document.querySelector(“.main-content”).classList.add(“backgroundimage-404”);
I would not go for the page title as the trigger element – that’s a customizable string. You should have the class template-404 applied to your body element. Using that, you can react on it using plain vanilla CSS. Of course you could also use this in a JS-condition.