简体   繁体   English

CSS文件未与html / php文件链接

[英]Css file not linking with html/php file

I have looked over the code and cant seem to see where the link between the two files is failing. 我查看了代码,似乎看不到两个文件之间的链接在哪里失败。 My index page uses the exact same code to link the files and it works fine. 我的索引页使用完全相同的代码来链接文件,并且工作正常。 When I add the styling in the header of the php/html file it works but otherwise nothing happens. 当我在php / html文件的标题中添加样式时,它可以工作,但否则什么也没有发生。

The reference that you have for the stylesheet is relative to the url of the page you're on. 您对样式表的引用是相对于您所在页面的URL的。

For example, this: 例如,这:

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

... says that the stylesheet is at the same path that the page is on. ...表示样式表与页面位于同一路径。 So if the url in the address bar is https://somewebsite/admin/index.php then that page will try to load the stylesheet at https://somewebsite/admin/style.css . 因此,如果地址栏中的网址为https://somewebsite/admin/index.php,则该页面将尝试在https://somewebsite/admin/style.css加载样式表。 If the url is https://somewebsite/index.php then the page will try to load the stylesheet at https://somewebsite/style.css . 如果url是https://somewebsite/index.php,则页面将尝试在https://somewebsite/style.css加载样式表。

If the stylesheet resides at the root of the site then your link tag should look like this: 如果样式表位于网站的根目录,则您的链接标记应如下所示:

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

This will make your page look for the stylesheet at https://somewebsite/style.css regardless of what the path of the url says. 无论URL的路径说什么,这都将使您的页面在https://somewebsite/style.css上查找样式表。

You should make the right path, right into your css file at 您应该输入正确的路径,直接进入位于的CSS文件

Example: 例:

<link href="assets/css/blabla.css" rel="stylesheet">

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

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