I need some help in understanding how I can get the following HTML coding to work.
<!DOCTYPE html>
<html>
<head>
<title>YAHUAS</title>
<style>
body {
background-image: url("Pictures/Yahuas.png");
background-repeat: no-repeat;
background-size: cover;
}
</style>
</head>
<body>
Student data
</body>
</html>
Should I be changing the following - background-image: url("Pictures/Yahuas.png"); so that it goes to the folder in the C:\Users\user\OneDrive - Bradford College\Advance Database\YAHUAS\PHP and HTML where this image is stored?
If the Pictures folder is located in the same path as your html file is, then it should work. Could you double check that the Pictures folder and your saved html file are in the same path?
I don't think you want to use the absolute path to the image unless you are going to view the html file only on your own computer. If you would put it on a web server or any other computer it is highly unlikely that the image would be found in the same path.
You should give to the exact URL Path
<style>
body {
background-image: url("./Pictures/Yahuas.png");
background-repeat: no-repeat;
background-size: cover;
}
</style>
Your Question is not really clear. However, I will assume you are trying to pick your image from the back of your folders/directories or from another Drive (e.g. C, D, F).
The Answer is Yes, You can Either use a backslash (Windows) or a forward-slash (Linux) with a full path or you can use a relative path if the image is present in the current directory or back directory.
<style>
body {
// Another Drive
background-image: url("C:/Users/user/My OneDrive/Pictures/pic.png");
// Relative Path
background-image: url("Pictures/pic.png");
// OR
background-image: url("./Pictures/pic.png");
// Back Directory/Folder
background-image: url("../Pictures/pic.png");
}
</style>
Related
I would like to set a background image to a div using CSS.
While I can display the image while using HTML <img src="/static/img/fon1.jpg">...
I get a 404 (Not Found) when I try to set the image through CSS:
style="background-image: url(/static/img/fon1.jpg)"\
I have tried different paths like: ../img/fon1.jpg and many others. Also with and withoud quotes.
I am certain that the css and the html are linked correctly as I can set the background to a solid color.
If I use in html, the css elements find and display the picture as well.
I feel like I should resort to just using <img> and rescaling it to fit the window, but I'd like to know what's wrong with the sucker.
Any kind of help / materials / links / jokes are welcome. Thank you if you take your time. All the best!
Folder structure:
project
└─static
└─ img
| fon1.jpg
└─ stylesheet
| styles.css
└─ base.html
HTML
<link rel="stylesheet" type="text/css" href="/static/stylesheet/styles.css">
...
<body>
<div class="background1"></div>
<div class="background2" style="background-image: url('/static/img/fon1.jpg')"></div>
</body>
...
CSS
.background1 {
background-image: url(../img/fon1.jpg);
height: 960px;
width: 1280px;
}
.background2 {
background: red;
height: 960px;
width: 1280px;
}
You missed the quotes in your code.
.background1 {
background-image: url('../img/fon1.jpg');
height: 960px;
width: 1280px;
}
I believe the proble lies in JetBrains Webstorm application. I tried the same configur on another application where I was hosting the server, and then the images were found. Currently I was using Webstorms feature to open local HTML file in browser. Seems that it doesnt support GET requests from .css file.
Update:
When referencing static files in Webstorm Live Edit the path should include the project folder. In my case the img would be located at: http://localhost:63342/projectname/static/img/fon1.jpg
I don't know from which file you are trying to access the image. I am assuming, You are trying from base.html
you are able to add the image like this.
<img src="./img/fon1.jpg">
I'm new to both HTML and CCS (I've just started yesterday night) and have hit a snag. I'm having some trouble with using the id selector in the div; the background image is failing to appear. Please note that external ccs was used and the image in question exists in a separate folder. Also, the code seen below was made using notepad on my Microsoft computer.
Here's what I've got so far:
#banner {
background-image: url("../img/Sunflower.jpg");
background-repeat: no repeat;
background-size: cover;
}
<link rel="stylesheet" href="css/style.css">
<div id = "banner">
Google Search
<br>
YouTube
<h1>First Web Page</h1>
</div>
There are several things that can go wrong:
In your CSS, you used a relative URL. Usually, Images are transfered over the web via HTTP, so usually, we put relative paths only when we use a bundler for JavaScript/Css. I recommend you change your image path to /img/Sunflower.jpg This will make your web-browser request it at <server_root>/img/Sunflower.jpg
Maybe you didn't include the actual CSS path in the HTML file to make the browser actually fetch it. Please check the <link> tag
The code you've written is generally okay, so the problem is with your actual filesystem / understanding of server paths, so I recommend checking those out.
Here's a working example for you:
#banner {
background-image: url("http://via.placeholder.com/300");
background-repeat: no-repeat;
background-size: cover;
}
<div id="banner">
Google Search
<br>
YouTube
<h1>First Web Page</h1>
</div>
Your code is correct and should work. Please consider the following.
1: Make sure you have the correct path of the image. Your path looks good from here, however, it is still hard to say because we don't know where you have saved the image.
2: Check and be sure that you have linked your CSS to your Html file if using the external CSS, or they are correctly placed in style tag if using internal CSS.
Thank you.
are you using inline css or external css file, or make a separate folder to your media and use that objects by giving simple names like img1.png like that
no-repeat instead of no repeat
please remowe spaces around equation marks - I've never seen anybody formatting the code like that
path to the image is most likely incorrect. Bear in mind ../ means one folder up relative to the css file
did you include your css file in HTML file?
Try add this line on header of HTML file:
<link rel="stylesheet" href="styles.css" />
where "styles.css" is the name of your css file. Check if the css file is in the same folder too.
I am trying to load a local image as background image in CSS. My folder structure as below,
MyApp
Public
index.html
html
template.html
images
myimage.png
javascripts
stylesheet
Loading index.html from public folder and on click, loading template.html from html folder. In template.html i have defined the css like this,
textarea{
<!-- background-image: url(http://i.imgur.com/2cOaJ.png); -->
background-image: url('../images/myimage.png');
background-attachment: local;
background-repeat: no-repeat;
padding-left: 35px;
padding-top: 10px;
border-color:white;
background-color: white;
height:90%;
width:95%;
resize: none;
outline-width: 0;
}
And calling this in template.html as ,
<div id="bodydata" class="tabcontent" >
<textarea rows="5" ng-model="description"></textarea>
</div>
It works beautifully when I take an image from web "background-image: URL(http://i.imgur.com/2cOaJ.png);" but does not work when I change to the local image which is nothing but the same image downloaded and saved as the local copy.
background-image: url('../images/myimage.png');
I want to have it as local because the server may not have the internet connection. So how to refer the image in right way. I have tried many things like single quotes, double quotes, without quotes but it didn't work. Please suggest.
Thanks in advance.
How is your web-server setup? Where is your web-server running from?
Depending on these answers, you should be able to achieve the desired result by adjusting your CSS like this:
background-image: url('/images/myimage.png');
So for instance, if your web-server is running in /MyApp, and is configured to allow static files to be fetched (eg files matching this pattern /images/*.png), then the answer above should work.
i am using background image for bottom of the header like this
header {
background:url(../img/header_bg.png) #ea6225 no-repeat;
background-size: 100% auto;
background-position:left bottom;
}
My images are in a folder like this Web/img/header_bg.png and css Web/css/style.css
now when i see in browser this image is being loaded but in console it shows error like this
file:///C:/Users/name/Desktop/Web/img/header_bg.png
net::ERR_FILE_NOT_FOUND
same this is happening with ttf fonts used in my project . Will someone help me whats wrong with it ?
According to W3, partial URLs are interpreted relative to the source of the style sheet, not relative to the document. You should set the URL accordingly.
try this:
background:url(../../img/header_bg.png) #ea6225 no-repeat;
You have to add "" like this ("../../img/header_bg.png")
Keep in mind,
<img src="Lanka.jpg"> <!-- Lanka.jpg is in the current folder -->
<img src="Asia/Lanka.jpg"> <!-- Lanka.jpg is in the Asia folder -->
<img src="/Asia/Lanka.jpg"> <!-- Asia folder is in root folder -->
<img src="../Lanka.jpg"> <!-- Lanka.jpg is in one folder up from current folder-->
I have domain 'A' with no hosting. I have domain 'B' with hosting.
I want domain 'A' to simply have a background image which it is referencing from domain 'B' hosting.
I have set up a directory in domain 'B' called 'bl' Within this folder I have placed a .jpg of the background image, 'bg.jpg' and also a style.css with the css3 code for having the background image full screen.
How do I point domain 'A' to this particular folder. Are there other elements besides the style.css and .jpg that I need?
If it helps, the only thing in the style.css file is:
html {
background: url(http://mywebsite.com/bl/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Thank you kindly for your assistance.
In this case, you will need to provide absolute path for your image with domain B. This way, you can call it on domain A.
<!DOCTYPE html>
<html>
<head>
<title>Testing - Stackoverflow</title>
<style type="text/css">
html {
background-image: url('http://blogsbits.com/wp-content/uploads/2013/01/Spring-Wallpaper.jpg');
background-repeat: no-repeat;
background-position: center;
}
.content {
margin: 0 auto;
width: 60%;
margin-top: 100px;
}
</style>
</head>
<body>
<div class="content">
<h1>Hi! Is This Usefull</h1>
<p>You can use any image that in the world wide web site. I just do it for give you more example. Just copy this code and create a new html page in your localhost. I got that image from google search. You need to get the image full path.</p>
<p><strong>Example : </strong></p>
<p>http://blogsbits.com/wp-content/uploads/2013/01/Spring-Wallpaper.jpg</p>
<p>This is the url that wich I viewed from google search engine. Click on it to view the image. Do the CSS styles also what type of you like</p>
<p>Hope you can understand this.</p>
<small>Wish you good luck on programming</small>
<p><small>Yeshan Sachitha K Perera # ITSthe1</small></p>
</div>
</body>
</html>
Create new html document in your localhost with this source code and run it. I hope you can understand this.
Forget about the existence of Domain B. It is irrelevant.
You need to:
Configure the DNS for Domain A to point at the IP address of the server which is running the webserver
Create (in the web server configuration) a new Virtual Name Host (that's the Apache documentation, if you don't use Apache you'll need to find the appropriate docs for your server) with a DocumentRoot pointing to that directory (on the file system. the existence of B is still irrelevent!)
Add an index.html file (you have to have a webpage for the background image to appear on).