CSS stylesheet not connecting with file on localhost, href |
CSS stylesheet not connecting with file on localhost, href |
james.R |
Apr 9 2017, 04:58 AM
Post
#1
|
Group: Members Posts: 4 Joined: 9-April 17 Member No.: 26,372 |
Hi All. I am new to the forum.
I have used external style sheets before but for some reason it will not connect on my local host. I hope someone can see what i am doing wrong. I am using localhost and the hosted folder name is call htdocs. In here i have a few folders: crm, css, graphics, web ect The file i am trying to connect the css on is login.php in the crm folder. The css file for this is in the css folder and called login.css I am trying to use the following to connect but having no luck. CODE <head link rel="stylesheet" type="text/css" href="http://localhost/css/login.css"> I have also tried the following variations CODE <head link rel="stylesheet" type="text/css" href="css/login.css"> <head link rel="stylesheet" type="text/css" href="localhost/css/login.css"> <head link rel="stylesheet" type="text/css" href="http://css/login.css"> Any help would be greatly appreciated. Thanks James |
CharlesEF |
Apr 9 2017, 05:50 AM
Post
#2
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
The CSS <link> should be in the <head> section (between <head> and </head>), not in the <head> tag itself.
This post has been edited by CharlesEF: Apr 9 2017, 05:51 AM |
james.R |
Apr 9 2017, 06:04 AM
Post
#3
|
Group: Members Posts: 4 Joined: 9-April 17 Member No.: 26,372 |
Thanks CharlesEF silly mistake on my end. Have corrected but still not working. First time using a local host and im trying lots of different combinations of the link to try and make it work.
|
james.R |
Apr 9 2017, 06:08 AM
Post
#4
|
Group: Members Posts: 4 Joined: 9-April 17 Member No.: 26,372 |
Sussed it.
CODE <head> <link rel="stylesheet" type="text/css" href="\css\login.css"> </head> I missed the "\" before the css\login.css |
james.R |
Apr 9 2017, 06:08 AM
Post
#5
|
Group: Members Posts: 4 Joined: 9-April 17 Member No.: 26,372 |
Thanks for the help though i wouldnt have spotted that.
|
CharlesEF |
Apr 9 2017, 06:17 AM
Post
#6
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Glad you got it working. When using paths in a web server it is always better to start the path with '/'. The '/' means to start in the root folder/directory. href="http://localhost/css/file.css" and href="/css/file.css" mean the same thing (also applies to 'src=').
|
Christian J |
Apr 9 2017, 07:46 AM
Post
#7
|
. Group: WDG Moderators Posts: 9,653 Joined: 10-August 06 Member No.: 7 |
CODE <head> <link rel="stylesheet" type="text/css" href="\css\login.css"> </head> I missed the "\" before the css\login.css Note that backslashes should only be used in Windows' local file system. On a server (local or on the web) you should use forward slashes as usual. As a sidenote, you can use relative URLs as well, even though it's usually less practical. Since the login.php file is in the crm folder (a folder which is parallell to the css folder), you would then need to go up one level first: CODE <link rel="stylesheet" type="text/css" href="../css/login.css"> See also http://htmlhelp.com/faq/html/basics.html#relative-url |
pandy |
Apr 9 2017, 10:12 AM
Post
#8
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,730 Joined: 9-August 06 Member No.: 6 |
I don't think backslashes should be used at all. Browsers are more lenient now, but do all browsers really accept them? It used to be only IE. And that was for local files. This is over a server, even if it runs on the same machine.
|
Lo-Fi Version | Time is now: 19th April 2024 - 02:57 PM |