[英]connecting header.php up a file level
I'm trying to connect my PHP header from a file that is in a folder. 我正在尝试从文件夹中的文件连接我的PHP标头。
I'm attempting to do this by using: 我正在尝试通过使用以下方法来做到这一点:
<?php include("../header.php"); ?>
It works to bring the content in that file on the page, but its not applying the style.css file to the doc. 它可以将内容带到页面上的该文件中,但是不会将style.css文件应用于文档。 Why? 为什么?
Here is the contents of header.php: 这是header.php的内容:
<!DOCTYPE html>
<html>
<head>
<title>%TITLE%</title>
<link href='http://fonts.googleapis.com/css?family=Lilita+One' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Roboto:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="includes/normalize.css">
</head>
<body>
<header>
<div class="page-wrap">
<h2 id="logo">Some Company</h2>
<nav>
<a href="index.php">Home</a>
<a href="contact.php">Contact</a>
<a href="rentals.php">Rentals</a>
<a href="forsale.php">For Sale</a>
</nav>
</div>
</header>
<section id="mainContent">
This is probably because its trying to reference the css at 'style.css' but try putting '../style.css'. 这可能是因为它试图在“ style.css”处引用css,但尝试将“ ../style.css”放入。 It should allow the styles but it won't fix all your pages. 它应该允许样式,但不能修复所有页面。 In that case its better to use something like this: 在这种情况下,最好使用以下内容:
<?php
// Set a constant with your url
define('BASE_URL', 'http://localhost:64411/TestingPHPStuff/');
echo 'Now use it in your html like this:';
?>
<link rel="stylesheet" type="text/css" href="<?=BASE_URL;?>style.css"/>
That way file location does not matter. 这样文件位置无关紧要。
Basically though, you are trying to use a stylesheet that doesn't exist at that current level. 不过,基本上,您正在尝试使用该当前级别不存在的样式表。 Probably. 大概。
Edited I changed it. 编辑我改变了它。 If you include the 'http://' and the port ':64411' (for example you would use your port) then it should work. 如果包含“ http://”和端口“:64411”(例如,您将使用端口),则它应该可以工作。 I just tested it and it only worked for me with both 'http://' and ':64411'. 我刚刚对其进行了测试,它仅对'http://'和':64411'都适用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.