importing CSS into a HTML does not work

后端 未结 3 1188
小鲜肉
小鲜肉 2021-01-29 13:55

I am trying to @import CSS file into an HTML but it does not work. I did try linking path, It is not working either.




        
相关标签:
3条回答
  • 2021-01-29 14:25

    Docs:

    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style

    https://developer.mozilla.org/en-US/docs/Web/CSS/@import

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title>Lesson</title>
    <meta charset="utf-8">
    <style>
       @import url("./FILE.css");
    </style>
    </head>
    <body>
    
    <script src="assets/script/U5.js" ></script>
    
    </body>
    </html>
    
    0 讨论(0)
  • 2021-01-29 14:26

    YESSSSSS!! I finally found how to do that. i just copied HTML path and wrote it as style path. Example for HTML;

    href="http://127.0.0.1:54149/assets/pages/U5-JS.html"
    

    so this is the style tag after change;

    href=''http://127.0.0.1:54149/assets/style/U5.css'' 
    

    So it perfectly works. I still do not know what was wrong. Thanks again all efford guys, i appreciated.

    0 讨论(0)
  • 2021-01-29 14:32

    If your CSS file is in the same directory use this:

    <link rel="stylesheet" type="text/css" href="./U5.css">
    

    If this HTML file is at the root use:

    <link rel="stylesheet" type="text/css" href="/assets/pages/U5.css">
    

    Use https://www.w3schools.com/Tags/tag_link.asp for more information on linking to external style sheets

    0 讨论(0)
提交回复
热议问题