【问题标题】:html relative address to css style sheet not workinghtml相对地址到css样式表不起作用
【发布时间】:2018-03-15 04:39:53
【问题描述】:

对于树莓派上的 apache 服务器,我有一个 linux 文件夹结构如下:

/var/www/html/index.html
/var/www/css/style.css
/var/www/php/someCode.php

index.html如下:

<!DOCTYPE html>
<html>
<head>
 <title>Introducing CSS Not Working</title>
 <link href="../css/style.css" type="text/css"
 rel="stylesheet" />
</head>
<body>
 <h1>From Garden to Plate Not Working</h1>
 <p>A <i>potager</i> is a French term for an
 ornamental vegetable or kitchen garden ... </p>
 <h2>What to Plant</h2>
 <p>Plants are chosen as much for their functionality
 as for their color and form ... </p>
</body>
</html>

style.css如下:

body {
font-family: Arial, Verdana, sans-serif;}
h1, h2 {
color: red;}
p {
color: #665544;}

css 不会影响 html。你知道为什么吗,我猜想与index.html中的css链接有关?

【问题讨论】:

  • 查看浏览器开发者工具中的网络标签,看看它是如何尝试解析 CSS 文件的路径的。
  • 谢谢,我该怎么做? (铬顺便说一句)

标签: html css hyperlink relative-path


【解决方案1】:

css 文件不在根目录中,我会将其移动到 index.html 所在的同一目录中,或者如果您需要 css 文件夹,我会像这样创建它们

/var/www/index.html
/var/www/css/style.css 
/var/www/php/someCode.php

【讨论】:

  • apache2文件夹结构使用var/www/html。对于我有组织的大脑来说,将 html 嵌套在 www 中似乎毫无意义。不过,我想继续我的生活,所以将/css/php 放入/var/www/html。它似乎有效。
猜你喜欢
  • 1970-01-01
  • 2023-04-04
  • 1970-01-01
  • 2012-12-08
  • 2014-06-05
  • 2019-08-27
  • 2016-04-02
  • 2017-01-15
相关资源
最近更新 更多