CSS being rendered as HTML in CodeIgniter
My css file present in css/style.css :
body {
background-color: #fff;
margin: 40px;
font-family: 'Lucida Grande', Verdana, Sans-serif;
font-size: 14px;
color: #4F5155;
}
When I run the site in a browser, there is no styling to the controller page , and the path to the css file returns this:
<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开发者_Python百科> </div>
</body>
</html>
Any ideas on what's going on here ?
Your stylesheet can't be found, most likely because it isn't on the path you think it is.
Things to check:
What do you think your stylesheet's path is (i.e. what did you type in the browser to get that 404 error?)
Where is the file in the filesystem in relation to your CodeIgniter root?
Are you using a .htaccess file? If so, what's in it? The .htaccess redirection done in CodeIgniter can confuse you.
The "standard" setup for CodeIgniter css files is this:
Save your css file in a "css" directory in the root of your CodeIgniter install, i.e. alongside the top-level index.php and .htaccss.
Make sure your .htaccess rewrite excludes the css directory, e.g.:
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
<-- note "css" is among the patterns to avoid rewrites for here. Otherwise CodeIgniter will think that "css" is a controller, not the actual directory on disk.Include your CSS file in your HTML file using something like:
<link rel="stylesheet" href='<?php echo base_url()?>css/style.css' type="text/css" media="screen, projection" />
.Obviously, make sure that your
base_url
is set correctly in your application's config\config.php file.
精彩评论