我正在学习php并遇到一些困难,我试图将php文件包含在另一个文件的头中,但是css没有工作吗?
下面是我的项目目录结构项目结构
这是我的php代码..。blogpage.php
<html lang="en">
<head>
<?php include 'head.php';?>
<title>Off Canvas Template for Bootstrap</title>
</head>我已经将路径包含在Struts-2/blogpage.php中。
这是我的head.php
<!-- Bootstrap core CSS -->
<link href="/css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/offcanvas.css" rel="stylesheet">
<link href="css/blog.css" rel="stylesheet">发布于 2016-10-09 14:54:44
CSS文件夹是否位于head.php下?
尝试向所有链接添加斜杠:
<!-- Bootstrap core CSS -->
<link href="/css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="/css/offcanvas.css" rel="stylesheet">
<link href="/css/blog.css" rel="stylesheet">您可以检查,直接添加链接,而不包括th php。试着这样做,看看链接是否有效。
发布于 2016-10-09 15:14:19
解决方案一:
根据您的文件夹结构,您在CSS folder下拥有所有的CSS folder,并且您正在尝试将其包含在位于outside、CSS folder的provide中,以及您必须将其直接指向CSS folder的过程,以便链接到在head.php中提供的所有文件。
head.php应该是这样的,这样它就不会涉及任何错误。
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet" type="text/css">
<!-- Custom styles for this template -->
<link href="css/offcanvas.css" rel="stylesheet" type="text/css">
<link href="css/blog.css" rel="stylesheet" type="text/css">错误:
bootstrap.css中,因此该文件不会在blogpage.php页面中调用。这就是你没有把css转到blogpage.php的原因。type="text/css"缺少head.php中的样式表调用,这也可能导致错误。为此,您需要在head.php中调用blogpage.php,如下所示:
<html lang="en">
<head>
<?php include ('../head.php'); ?>
<title>Off Canvas Template for Bootstrap</title>
</head>最佳做法
但是您可以将所有的head.php、footer.php、header.php封装到includes folder中,这样它将是该文件夹下的常量,并且您可以提供链接而不出现任何错误。
由于您在Struts-2文件夹中调用它,您的路径有时可能会失败,而CSS可能会导致错误。
提示:一个站点已经完全加载,您可以按
CTRL+U键,这样您的整个代码就会在新窗口(查看页面源)中打开,并且您可以检查在浏览器中正在执行的所有链接是否正确。
解决方案二:
您可以将正斜杠加到CSS文件夹结构中,因为当您试图将它添加到您使用的任何页面时,它不会失败。因为所有的通信都将在所有调用的根目录下完成。
你的head.php看起来就像
<!-- Bootstrap core CSS -->
<link href="/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="/css/ie10-viewport-bug-workaround.css" rel="stylesheet" type="text/css">
<!-- Custom styles for this template -->
<link href="/css/offcanvas.css" rel="stylesheet" type="text/css">
<link href="/css/blog.css" rel="stylesheet" type="text/css">https://stackoverflow.com/questions/39944833
复制相似问题