Linking html with css with relative path


#1

Hello all! >> newbie question … sorry <<

i’ve completed this lesson,
https://www.codecademy.com/en/courses/learn-html-css/lessons/css-setup/exercises/html-link-css
but i’m having trouble implementing it on my own.

If i link my html with css with the exact path, it works perfectly fine, but if i try to make it a relative path (both files are in the same folder) it doesn’t work. Can’t figure out what i’m doing wrong.



<head>
    <title>My Web Page!</title>
    <link
  href="C:/_coding_/1st%20try/1st_try_style.css" 
  /* href="/1st_try_style.css"  */
  type="text/css"
  rel="stylesheet" />
  </head> 


so, right now i have ‘href=“C:/coding/1st%20try/1st_try_style.css”’ active and is working fine

but if i “comment it out” and put this instead 'href="/1st_try_style.css"'
it does not apply the css contained styling any more. Surely i have made some mistake declaring it’s value, but what? Where is my mistake? Please help me see it. Thank you.


#2

Have you tried leaving out the backslash
like
href="1st_try_style.css"


#3

thank you for your reply :slight_smile:
yes, i’ve tried that :slight_smile: unfortunately it made no difference


#4

scratch that… i’ve just tried it again, and it works!!! don’t know what i did before, but i sware i tried it… i also tried every combination i could thing of so i’ve probably combined it with smth i was not supposed to… either way it works now! and your answer was spot on! THANK YOU! :slight_smile: :smiley:


#5

read a discussion
https://stackoverflow.com/questions/10659459/starting-with-a-forward-slash-in-html-for-href


#6

wow… some of those posts / links are not an easy read for me at this point, but it IS helpful as i’m slowly beginning to see the light, even if it’s not crystal clear yet, things are starting to take shape :slight_smile: Thank you again for your willingness to help me :slight_smile: *hug


#7

As an extra
https://css-tricks.com/quick-reminder-about-file-paths/
with the explanation what it meant when using
href="/1st_try_style.css"
it would point to
root/1st_try_style.css


#8

You don’t have to copy the slash you can type when your website goes online it will work fine.

If not try your own… href="/1st_try_style.css" this will also works…


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.