我想知道是否有人可以帮我解决我第一次使用HTML,CSS ...和PHP创建网站时遇到的一些问题。 (我以前在网页设计方面的尝试仅限于HTML和CSS)。
目前的问题是我的主页(index.php
)在某种程度上没有看到'我的stylesheet.css
。
index.php
的代码基本如下:
<?php
$page_title='Home';
[php-code here, to call in include1.php.....Please see below for details]
?>
<div class="copy">
[page content here, in html]
</div>
<?php
[php-code here, to call in include2.php.....Please see below for details]
?>
我的文件夹结构是: 网络
css
stylesheet.css
images
logo.png
includes
include1.php
include2.php
index.php
在尝试调用include1.php
(包含文档类型声明和包含对stylesheet.css
的引用的主题部分)时,我尝试了以下内容(在<?php
和{{}之间插入{1}},如上所示),都没有成功:
?>
和
$pathtoinclude1 = $_SERVER]'DOCUMENT_ROOT'];
$pathtoinclude1 .= "/includes/include1.php";
include_once($pathtoinclude1);
在include('/includes/include1.php')
中,我对include1.php
的引用是:
stylesheet.css
当我预览主页时,我得到的是默认字体(Times New Roman?)的文本。没有通过CSS的样式被应用。
任何人都可以给我一些关于我做错事的指示吗?
答案 0 :(得分:1)
如果第一个答案不起作用,请尝试替换
<link rel="stylesheet" href="../css/stylesheet.css" media="Screen" type="text/css">
<?php include 'style.php'?>
然后在style.php文件中包含<style>
标记,然后定期添加css。
答案 1 :(得分:0)
php
,请确保您拥有正确的html
声明。虽然您已经与html,css
合作过一个提醒:
<?php
$page_title='Home';
[php-code here, to call in include1.php.....Please see below for details]
?>
<!DOCTYPE html>
<html>
<head>
<!-- MAKE SURE YOU'RE INCLUDING THE
EXTERNAL CSS FILE HERE BUT NOT TO INCLUDE YOUR PHP INCLUDES!
WHICH ACCORDING TO YOUR FILE STRUCTURE SHOULD BE -->
<link rel="stylesheet"
href="../css/stylesheet.css"
media="Screen"
type="text/css"/>
</head>
<body>
<div class="copy">
[page content here, in html]
</div>
<?php
[php-code here, to call in include2.php.....Please see below for details]
?>
</body>
</html>
答案 2 :(得分:0)
当include()
index.php
文件时,路径如下:
<link rel="stylesheet" href="../css/stylesheet.css" media="Screen" type="text/css"/>
此路径从index.php
返回一个目录,该目录不是有效路径。当您将include1.php
中的路径包含在index.php
中时,其路径应如下所示:
<link rel="stylesheet" href="css/stylesheet.css" media="Screen" type="text/css">
此外,如果CSS包含正确但样式仍未显示,请尝试删除浏览器缓存。
答案 3 :(得分:-1)
尝试一下。它对我有用
假设您的CSS文件名为“ css.css”
它与您的主页位于同一目录中。
只需将其添加到head标签:
Head
Style
<?php include('css.css') ?>
style
head
别忘了添加相应的标签