Background image is not showing because of image path problem.
css code
background-image: url("images/menu_home_icon.png");
My actual image path is EZ_MOVERS/images/menu_home_icon.png.
But it shows EZ_MOVERS/css/images/menu_home_icon.png while I checking through Inspect Element.
I can't find from where /css comes.
Anybody help please ?
Probably because the stylesheet is located in the /css folder. Remember that the paths in the file are relative to the stylesheet's path. Based on my understanding, your directory structure looks a little like this:
EZ_MOVERS
│
├── css
│ └── <stylesheet>.css
└── images
└── menu_home_icon.png
So if you want to traverse a directory up and then select the /images sibling folder, use ../images/menu_home_icon.png.
Related
I'm setting up pages on my personal website(hugo academics by wowchemy) and here is the structure of one of the folders I have:
.
├── ABF.md
├── EXE.md
├── Figures
│ ├── sampling.gif
│ └── sampling_compressed.gif
├── HREMD.md
├── MetaD.md
├── REUS.md
├── TREMD.md
├── US.md
├── _index.md
├── alchemical_MetaD.md
├── appendix.md
├── intro.md
└── test.gif
In _index.md, I have the following lines to read in a GIF file:
<center>
<img src="Figures/sampling_compressed.gif">
</center>
In intro.md, which is in the same folder as _index.md, I also have the same lines to read in the same GIF file. However, in localhost, the GIF file is shown in the page made by _index.md, but not the one built by intro.md. How can I solve the problem and why is this happening? Thanks in advance!
Your assumptions about the output structure are wrong. Hugo builds _index.md in the root of you folder, while the intro.md file (when processed with pretty URL's) is built in a subfolder: intro/index.html.
That being said... I tested your setup and an image in a Section directory (which is a directory with an _index.md file) is not processed by default. I would solve this by moving the image to the static directory so you can reference it from any file in the same way (with an absolute path), especially because this image does not belong to just one page.
If it WERE to be used by just one page, you could have turned the intro.md into intro/index.md and make that directory a Page bundle in which you could put your image and reference it by using the resources variable.
I am combining many small semi-static, single-page webapps into one larger web site. The backend is a lot of proxies, but the forward facing server basically just make it look like the app was moved from the root filepath to a more specifics one. IE:
/
├── css
│ └── app1.css
├── index.html
└── js
└── app1.js
would be moved to
/apps/app1/
├── css
│ └── app1.css
├── index.html
└── js
└── app1.js
This migration has been relatively painless mainly due to the use of ./ in the apps' html files, such that most apps just load their resources relative to their new location. The problem I am having is that some apps are resolving ./ differently. For these trouble cases, the primary html file gets loaded; however, the ./ in the script and style elements are resolving to a higher file-path (IE: I would expect ./ to resolve to /apps/app1 but am getting /apps). It may be a coincidence, but the troubled apps often have additional, non-index HTML files.
What are the rules for how ./ is resolved?
Determine the base URL
This is usually the URL of the HTML document
It might be overridden by the base element
For CSS it is the URL of the stylesheet
JS is always with respect to the HTML document
Remove everything after the last / in the path section of the URL
e.g. the base URL for https://example.com/example/foo?bar=baz#fragment is https://example.com/example/
Keep in mind that an HTML document might be visible at the path /example and /example/ and you should avoid this by making one path canonical (I prefer the one that ends in a /) and redirecting to it from the other
Strip the ./ from the front of the relative path
Append the result of step 3 to the result of step 2
A common gotcha is to confuse URLs with file paths. While a simple static site will usually have a direct 1:1 mapping between them, many modern sites will use routing code (e.g. for Express for HTML documents and a separate static route for static files like images, js and css.
I am trying to deploy some ui components on Netlify. However, it is not recognizing my index.html files inside the subfolders. Hence nothing is showing up on my deployed site. Also, all 3 index files have links to each other. This is my file structure
├── ui-components
├── blog-cards
│ └── index.html
├── login
│ └── index.html
├── ads-manager
│ └── index.html
Do I have to delete my subfolders and bring out my index files for it to deploy on Netlify or is there any way around it?
Edit:
I made some progress by doing this instead by putting a _redirects file in the root of my app as suggested
/ /blog-cards/index.html 200
/login /login/index.html 200
/ads-manager /ads-manager/index.html 200
It's finding my index.html inside the blog-cards folder however it's not loading my css file now. Full folder structure
├── ui-components
├── blog-cards
│ └── index.html
│ └── style.css
│ └── images
Here's a link to the netlify site
You don't have a main index.html file, which is why nothing is showing up on your deployed site. You should add something there, even just a blank page or a placeholder with links to the other projects.
You probably don't have to though, just browse to <siteurl>/ui-components/blog-cards and that should work.
Update after further comments.
If there is a subfolder you want the site to automatically go to upon landing, then you can use Redirects.
For example, putting the below in a file called _redirects in the root of your app will do what I think you need:
/ /ui-components/blog-cards 200
/login /ui-components/login 200
/ads /ui-components/ads-manager 200
(the 200 status code means that it will be a redirect under-the-hood, which makes the URL stay clean as you have said.)
Update
Yeah, so the forwarding is making the .css files to fail to load.
<link rel="stylesheet" href="style.css"> will look at the current URL and add style.css to it, which is obviously not what you want.
You could change to forwarding it with a 302, which would mean the new (not nice) URL would show up, but then the css path would resolve correctly.
Alternatively, you could add a second stylesheet link that looks for ./blog-cards/style.css.
Or if the css is small enough you could inline it, making it all simpler.
I am having an issue getting my background-image to load as a live website (using github pages). When i load it locally I can get it to work by entering in the full directory. However when I then move it to Github the directory changes and so it no longer works. To summarise, when I use background-image url("images/picture.jpg"); it will not work at all. I have to type in background-image url("c/onedrive/webroot/images/picture.jpg"); so the whole file name. However that does not work when put onto Github. Any help would be much appreciated. (:
As others mentioned, it seems like a file path issue. When using relative paths like images/picture.jpg, make sure the target image is in the correct relative location as indicated. If your images folder is located at the project root, your background-image url had safer/better be /images/picture.jpg with the / at the beginning to denote the project root.
Update
Looking at your code on the repo, I fixed it by updating the relative path — background-image: url("../images/abstract.jpg");
Your folder structure looks like...
/
|
├── css/
├── images/
├── js/
├── objects/
└── video/
Since your stylesheet in css folder is pointing to a file in images folder, you'd need to use a correct relative path.
I have faced this problem before. If you're background-image doesn't work check if your path is correct you could also right click the image in the file browser open Properties
--> Security and copy the path from there. If this doesn't work copy the image address directly from the browser and paste it there.
Check your path is correct
body {
background-image: url("path_of_image_from_this_page.jpg");
}
I am running a simple HTTP server using python. I have an HTML file with the following script tag:
<script src="../../build/react.js"></script>
The file is present in the right place if the relative URL is followed, but both Chrome and Firefox, look for base/build/react.js instead of base/../../build/react.js.
I remove the relative path, and it works fine as expected. Why are the relative paths not working?
Perhaps could you define "base"?
My answer assumes that "base" is the "base URL/domain" of your website:
e.g. base == http://www.google.com/
The base directory is essentially acting as the root of your directory... accessing the parent of the root directory is a logical fallacy (a root has no parent). When you seek the parent of a root directory, most programs will simply return the root.
For example, I'm assuming your site has the following layout:
www.google.com/
├── css/
│ └── theme.css
├── js/
│ └── jquery.js
└── html/
└── home.html
Suppose home.html uses the following code:
<link href="../css/theme.css" rel="stylesheet">
<script src="../../js/jquery.js"></script>
Because the parent directory of html/ is the root directory, both will translate to:
www.google.com/css/theme.css
www.google.com/js/jquery.js