简体   繁体   English

将css文件链接到我的html文件

[英]linking a css file to my html file

I am having way too much trouble figuring out how to link a .css file to my .html file. 我在弄清楚如何将.css文件链接到我的.html文件时遇到了太多麻烦。 They are both in the same folder on my desktop. 它们都在我的桌面上的同一文件夹中。

I created the these in sublime and when I made the styles.css I did saveas selected the folder on my desktop that my html was in and then saved it as a css file. 我以崇高的态度创建了这些文件,当我创建styles.css时,我确实进行了另存为,选择了我的HTML所在的桌面上的文件夹,然后将其另存为css文件。 Something that might be the problem is when I look at the files in the folder, the html say filename.html but the css just says style without the .css and the file type is file. 可能是问题所在,当我查看文件夹中的文件时,html表示filename.html,但css只是表示样式而没有.css且文件类型是file。 I tried to go into the properties and change it to .css but that also didn't work. 我试图进入属性并将其更改为.css,但这也没有用。

This is the html file I have tried "/style.css" , "foldername/style.css" , and the entire path 这是我尝试过的html文件“ /style.css”,“ foldername / style.css”和整个路径

<html>


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

<body>

<div class ="test">
    test
</div>

</body>

</html>

This is the css file with the file name of style.css 这是css文件,文件名为style.css

.test{color:green; margin:50px;}

Did you name your CSS file "styles.css" or "style.css?" 您是否将CSS文件命名为“ styles.css”或“ style.css”?

When working locally, make your css paths relative. 在本地工作时,请使css路径相对。 So it would look something like this: 所以看起来像这样:

<link rel="stylesheet" href="../styles.css">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM