+ 2
What am I doing wrong with this image?
Iâm trying to use an image as my background and the code is as follows (CSS): body { background-image: url(âhttps://goo.gl/images/VQCSBkâ); background-repeat: no-repeat; } Whenever I run there is still just a blank background. Help
13 RĂ©ponses
+ 2
It seems that the reason why the image isn't displaying is because the link doesn't exactly lead anywhere. When including URLs to images in HTML or CSS, you would need to provide a link that leads directly to your image, which could be done by right clicking (or long pressing on mobile) on the image and pressing "view image in new tab".
+ 1
you were right faisal. thanks
0
I think these too.
0
what if I want to use an image in my /root folder?
0
Nicholas Johnson , you can simply define the local path. for example,
<img src="/root/test.jpg" alt="">
but as a best practice,I would recommend that you create a specific folder for images so that later on, it'll be easier for you to attach your images into the webpage.
0
arif asyraf I found that when i put the images in their own folder they won't load unless my html document is saved in the same folder as the images. but I want to add a background image using html and not have to call in a stylesheet
0
Nicholas Johnson have you specified the image source correctly? usually, i will create one folder for a project and then create the subsequent folders for them like img,js,css and all accordingly.
for your question, you can try this,
<body style="background-image:url(/root/test.jpg)">
</body>
I'm not sure if this is correct because I haven't done it this way for a long time.
I encourage you however to use stylesheet so that your code look cleaner.
0
arif asyraf thank you for your reply, I appreciate it. also where does the last double quote go in your code you wrote?
0
Nicholas Johnson oh, silly me. Thank you for pointing that out, I missed it. edited the answer.
0
arif asyraf no problem. yea, code didn't work. oh well, CSS it is lol
0
Nicholas Johnson yea, sorry about that. CSS will be fun. I'd recommend you to look into SASS once you're done with css for a more entertaining experience with CSS. Happy coding, my friend đ
0
thank you again my friend.