lit*_*leK 5 html css php include
如果我在PHP页面上包含HTML页面(例如,index.php),则包含以下内容:
<?php
include ("../../forms/login/form.html");
?>
Run Code Online (Sandbox Code Playgroud)
那么form.php会在index.php中正确显示吗?当我正确地说,我的意思是它的所有图像和CSS.
我问的原因是因为我的情况并非如此.我试了一下,它会显示form.html但没有任何造型......
任何帮助将不胜感激,谢谢!
更新:
目前,我在forms.html上有以下内容:
<link href="view.css" media="all" rel="stylesheet" type="text/css" />
<script src="view.js" type="text/javascript"></script>
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
Run Code Online (Sandbox Code Playgroud)
现在,forms.html自己正确显示.
在index.php上,我有:
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>UofS :: Residence Life Management System</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
include ("html/header.html");
?>
<?php
include ("php/navigation.php");
?>
<br></br>
<?php
include ("forms/login/form.html");
?>
<br></br>
<?php
include ("html/footer.html");
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
对forms.html的唯一引用是通过php include().没有样式表指向它.这是无法正确加载forms.html的页面.这不对吗?
谢谢!
Sco*_*ers 10
样式表的路径可能是相对的.它需要相对于浏览器中的url(index.php).或者让它成为一条绝对的道路.
自更新以来编辑:view.css和view.js将不会被加载,因为它们的路径是相对的.从index.php页面使这些路径成为绝对路径或相对路径.无论何时在任何地方包含form.html,使它们绝对会使它们起作用.从index.php创建路径相对将使它们从那里包含时可以工作,但是当从其他目录中包含时不会.
更好的是,如果您知道需要加载这些文件,请将链接放在index.php页面而不是form.html页面上.
另请注意,您可以使用以站点根目录开头的路径,您不必包含主机和域名:
<link href="/css/style.css" rel="stylesheet" type="text/css" />
Run Code Online (Sandbox Code Playgroud)
"css/style.css"之前的斜杠将使这个绝对路径可以在你的live和dev服务器上运行.
编辑...
假设您的index.php文件位于根级别,请在forms.html中尝试:
<link href="/forms/login/view.css" media="all" rel="stylesheet" type="text/css" />
<script src="/forms/login/view.js" type="text/javascript"></script>
<link href="/css/style.css" rel="stylesheet" type="text/css" />
Run Code Online (Sandbox Code Playgroud)