How to link a .css file from HTML file?

后端 未结 2 1664
悲&欢浪女
悲&欢浪女 2021-01-27 00:34

I have been learning HTML5 and CSS, until now I have been styling in the HTML section. When I tried to move s

2条回答
  •  长情又很酷
    2021-01-27 00:56

    Why does linking a CSS file not work?

    In your example, you only have to change the rel="Hope this works" to rel="stylesheet" in order for it to recognize it as a stylesheet, as demonstrated in the following:

    This is simply in order to distingush the difference between say a stylesheet link and an icon image link. This link to a w3 Schools page describes the possible values for the attribute rel.


    Furthermore, if it still doesn't work, ensure that the file "newcssstyle.css" is in the same directory as the referenced HTML file. If you put it in a folder such as "stylesheets", ensure that you add the relative folder path to your HTML file.

    For example, if you had a directory like this:

    • Parent Directory Name:
      • index.html
      • Stylesheets:
        • newcssstyle.css

    Then you would refrence "newcssstyle.css" (relative to "index.css") as href='Stylesheets/newcssstyle.css'

    Whereas, in a directory like this:

    • Parent Directory Name:
      • Html_files:
        • index.html
      • Stylesheets:
        • newcssstyle.css

    Then you would refrence "newcssstyle.css" as href='../Stylesheets/newcssstyle.css' instead (where .. means "go back a level to the parent directory").


    If the problem still persists, it may be your browser is not compatible with your specific HTML or CSS version. Internet Explorer, for example, it known to be a terrible browser. If you use it, just get Chrome.

提交回复
热议问题