我的css文件存在于css / style.css中:
body {
background-color: #fff;
margin: 40px;
font-family: 'Lucida Grande', Verdana, Sans-serif;
font-size: 14px;
color: #4F5155;
}
当我在浏览器中运行该站点时,控制器页面没有样式,并且css文件的路径返回:
<html>
<head>
<title>404 Page Not Found</title>
<style type="text/css">
body {
background-color: #fff;
margin: 40px;
font-family: Lucida Grande, Verdana, Sans-serif;
font-size: 12px;
color: #000;
}
</style>
</head>
<body>
<div id="content">
<h1>404 Page Not Found</h1>
<p>The page you requested was not found.</p> </div>
</body>
</html>
关于这里发生了什么的任何想法?
答案 0 :(得分:1)
无法找到您的样式表,很可能是因为它不在您认为的路径上。
要检查的事项:
您认为样式表的路径是什么(即您在浏览器中键入了什么来获取404错误?)
文件系统中与CodeIgniter根相关的文件在哪里?
您使用的是.htaccess文件吗?如果是这样,它里面有什么? CodeIgniter中完成的.htaccess重定向可能会让您感到困惑。
CodeIgniter css文件的“标准”设置如下:
将您的css文件保存在CodeIgniter安装根目录下的“css”目录中,即与顶级index.php和.htaccss一起保存。
确保您的.htaccess重写排除了css目录,例如:
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
&lt; - note“css”是避免重写的模式之一。否则CodeIgniter会认为“css”是一个控制器,而不是磁盘上的实际目录。
使用以下内容将您的CSS文件包含在HTML文件中:<link rel="stylesheet" href='<?php echo base_url()?>css/style.css' type="text/css" media="screen, projection" />
。
显然,请确保在应用程序的config \ config.php文件中正确设置了base_url
。