Can't link CSS to HTML in Eclipse Java project - html

I am building a web project at Eclipse in Java. I wrote a simple HTML and CSS files but I can't see how to link them and I can't spot the problem.
<link rel="stylesheet" type="text/css" href="css/AdminOptionCss.css" >
My files are located here:

you have to give a relative path of that css file , it means that :
your HTML's are in html folder , but your CSS's are not in html folder but your are trying to load them from html folder!
what you need to do is, go a step backward in directory by using ../ and continue pathing, something like this :
<link rel="stylesheet" href="../css/AdminOptionCss.css" >

Try to do like this
<link rel="stylesheet" type="text/css" href="../css/AdminOptionCss.css" >
../ help you to navigate out of html location path , and after go to css and so on

Change your Eclipse view to "Navigator" to see the real file path and use a relative path, like href="../css/AdminOptionCss.css" in your link tag.

Related

How to see css style on desktop (offline) and also on website (online)?

I have a style.css and a html files.
When I upload them to the server I see the headlines in the style I want but on my desktop I don't.
Both of my files are on the desktop
On the <head> I have this line in my html file:
<link rel="stylesheet" href="/style.css">
What can I do to connect the files and see the style applied when I'm offline working on my desktop? and also online in my website
i want to add i just removed the / and it works offline on my desktop (just href="style.css") but not online - but i want to be able to see it both online and both offline ---- and online its not in the same file
** edit : now i see that what works on both is if i put my spesific website adress - than it works on both online and offline :
but if i will want to ever change my website adress it would be hard to change on each page thats why i want it to be : href="/style.css and not the website adress
If you are working locally without a webserver you need to link your css files like this:
<!-- Windows -->
<link rel="stylesheet" href="C:\Path\to\File\main.css">
<!-- Linux & Stuff -->
<link rel="stylesheet" href="/path/to/file/main.css">
Additionally you could use the relative path to your file:
<!-- if it's in the same folder -->
<link rel="stylesheet" href="main.css">
<!-- if it's in the css folder -->
<link rel="stylesheet" href="css/main.css">
<!-- if it's in the parent folder -->
<link rel="stylesheet" href="../main.css">
your question is still not clear, but generally, your question seems to be based on the linking of the style sheet with your HTML file to see the results of your code on your personal laptop and the server both. The best practice to do that is to maintain a file structure which keeps the project organized, for example, there is a folder named "main" which is my project folder which further contains your subfolders like CSS and js, and inside these folders, you should keep your CSS and js files respectively.
A simple project file structure is,
main
|
|-css
|-style.css
|-js
|-script.js
|-file.html
If you follow the file structure to link your files, you won't go wrong, it doesn't matter whether you are on your personal desktop or on the server.
One thing i understood is that when you are working locally you have html files and the css file on the desktop. First of all i would recommend you to make a new folder and copy all your related files whether it be html files, css files or js files in that folder. It is a better way to encapsulate all your project files in a single folder.
Moving on to the css issue - you said that it works when you remove /. It works because since your files are all on desktop they are on same directory structure.
Enough for clarification I want you to follow these steps:-
First make a folder and copy your html files, css files and js files in it. Lets name the folder as website.
Create a folder named css inside the website folder. Copy all the css files in that css folder.
Inside your html files, inside the write <link rel="stylesheet" href="css/style.css"> provided that the name of css file is style.css and you want to include this particular file in your html.
And regarding your online issue, I am not able to understand it. If you clarify a bit more i may be able to help.
Your files should have the same relative path on your desktop and server, so that you can use that same relative path for both. The relative path is based on the location of your HTML file in both.
If you have a folder on your desktop that has 2 files:
index.html
style.css
Inside of index.html, you'll reference your stylesheet using <link rel="stylesheet" href="style.css">
If you have a folder on your desktop that has 1 file and 1 folder containing a file:
index.html
css/ (contains file: style.css)
Inside of index.html, you'll reference your stylesheet using <link rel="stylesheet" href="css/style.css">
Since you said that <link rel="stylesheet" href="style.css"> works correctly on your server, that means that your HTML and CSS files are contained in the same parent folder. On your local, you need to make sure that the same is true. That parent folder can be located anywhere - Documents, Desktop, a random subfolder - but as long as it contains that HTML file and that CSS file (and neither of them are nested in another contained folder), that <link rel="stylesheet" href="style.css"> will work for both.
Note: You can change the folder structure of either server or desktop, or both - but the relative paths must match, so that your relative link works for both.
give like this
<link rel="stylesheet" href="style.css">

My bootstrap website is working locally, but fails to load css and images when trying to publish it

I'm pretty much new to all of this and for the past days I've been working on my first Website using bootstrap. Locally, this works fine, but right now, when trying to get it up online, it looks like this:
http://wearemanjaro.de
Just ugly html, no css nor any images are loading.
I made the link above link to the html which is in the /manjarowebsitebootrap/robots/index.html path. The CSS (bootstrap and custom) is in the following directory: /manjarowebsitebootstrap/css/...
The link to CSS in my html looks like the following:
<link rel="stylesheet" type="text/css" href="../css/custom.css">
<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
Same problem with the images in my ../img folder. It all works fine locally. I'd really love some help or advice :)
First thing you need to do is use an absolute instead of a relative path.
if your directory structure is:
-root
--docs
---doc1.php
--includes
---header.php
---footer.php
---css.css
--index.php
In your header, you link to my CSS file like so:
<link href="includes/styling.css" type="text/css" rel="stylesheet" />
you need to do like this :
<link rel="stylesheet" type="text/css" href="/root/includes/css.css" />
You also need to use developer tools on chrome that will help you to debug these things.
I saw there that the images are not uploaded so once you able to upload them you will start getting them on the Website if the path is correct.
and best of luck for the new world of web development.:)
Your file structure has changed from local to online/live. I inspected your page, placed in the CDN for Bootstrap and pow, the styling came alive.
Use the following CDN to replace your current src='' path for bootstarp in your html head to see what I mean.
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css
The next steps you should take: make note of where all your files are living on your server, you must place all associated files on the server, as specified by your code, i.e shows that you have a CSS folder.
Also is this HTML file located at the same level as the CSS folder or does this HTML file live in a folder of its own. If not your paths do not need to include the ../ portion and you should use just css/yourFileName.css

Can't use css files in eclipse ee

I have made a .css file for a html i'm using in a dynamic web project. The css implementation clearly works because if i run the tomcat server from the html i can clearly see the css effect but if i run it from the main project it opens the same html page but without the css effect. How am i supposed to fix this? Do i have to write something into the web.xml file ?
This is the link tag in the html file
<link rel="stylesheet" type="text/css" href="style.css"/>
Am i supposed to add something else ?
it depends on location of css file. Your path will if css is in same folder as html/jsp file. If it is in sub folder in webcontent folder then use href="foldername/filename" if its in root folder then href="../foldername/filename"

How can I link my css file with my html in sublimetext 2?

My main doubt is the part of href.How can i avoid using the full link of the file as saved in my harddisk so that i dont need to change it while transferring through ftp.I also want to know how you can view your html files being developed that has been linked to different css files on your desktop web browser like chrome.
If your HTML file is stored in a directory, and your CSS files are stored, for example, in a css subdirectory, all you need to do is add
<link rel="stylesheet" type="text/css" href="css/mystyles.css">
to the <head> tags of your HTML file, and you'll be all set.
If the file is in the same folder as your HTML file you will simply type the name of the file
<link rel="stylesheet" type="text/css" href="style.css" />
Let's say that your style.css file is in another folder called css
<link rel="stylesheet" type="text/css" href="/css/style.css" />
By playing a "/" in front of your file name it is saying that it should look for the "css" folder starting from the root folder instead of the current location.
You can use relative paths. If the css stylesheet is in the same folder as the html use href="style.css". If it's in a folder that is in the same folder as the html use href="styles/style.css". If you need to go up a folder use href="../style.css".

Stylesheet link failure HTML/CSS

I've been working on a project with a HTML and an external CSS file. The link worked fine at school when i was doing it on adobe dreamweaver on a mac, but i sent both files home via dropbox, and the css doesnt seem to link with the html file. I believe i've got the file paths and everything right, but just to make sure:
<link rel="stylesheet" type="text/css" href="Desktop/Stylesheet.css" />
i also tried removing the "Desktop/" bit from the file directory, but it still didnt work. My Index file and Css file are both on my desktop. I am using windows. The same code worked at school, so i believe it might be something to do with with file location.
please help
Thanks in advance
This is how linking works,
Let's say your html file is in a folder named "xyz". Now when linking to css, the address is related to your html file's location. So if you mentioned
<link rel="stylesheet" type="text/css" href="Stylesheet.css" />
it would assume the css file is in the same folder as your html, while if you linked it as
<link rel="stylesheet" type="text/css" href="Desktop/Stylesheet.css" />
it would assume there is a folder named Desktop inside the folder xyz, and your css file is probably stored in Desktop.
Now im assuming you've simply placed both your html and css on your desktop directly, this is not good practice as you're probably going to move these files back to school as well. Hence I'd recommend you to place both in a folder and then link to your css with
<link rel="stylesheet" type="text/css" href="Stylesheet.css" />
and dont forget to pay attention to capitalization, yes html is non case sensitive but when it comes to linking external files, capitalization does matter.
Your directory structure should look as follows:
Root Directory
|
|-page.html
|-Desktop
|-StyleSheet.css
If it does not you need to modify your directory structure or change the href attribute on the link tag
If it is in the same directory simply set the path to href="Stylesheet.css"
The problem is with your file location .
If you are using Dreamweaver or any other code editor, simply browse to the path of the file to insert it in link href attribute, rather than manually entering the path .