|
引用css发现好多人提问过,但是我看了以往的提问帖子,还是没能把问题解决,所以发帖求助。
我用的CI2.1.4 版本,ubtuntu系统。
文件目录情况:
1.CI根目录为/var/www/CI/
2.css 文件在/var/ww/CI/css/mystyles.css
h1 {
margin: 5px;
padding-left: 10px;
padding-right: 10px;
background: #ffffff;
color: blue;
width: 100%;
font-size: 36px;
}
.test{
margin: 5px;
padding-left: 10px;
padding-right: 10px;
background: #ffffff;
color: red;
width: 100%;
font-size: 36px;
}
配置情况:
1.CI配置文件CI/application/config/config.php里面设置 $config['base_url'] = 'http:localhost/CI/'; $config['css'] = "css/mystyles.css";
2.存在CI/system/.htaccess CI/application/.htaccess CI/application/cache/.htaccess三个.htaccess文件,三个文件内容都改为
RewriteEngine on
RewriteCond $1 !^(index\\.php|images|js|css|robots\\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
控制器:CI/application/controllers/start.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Start extends CI_Controller {
function Start()
{
parent::__construct();
$this->load->helper('url');
}
function hello($name)
{
$data['mytitle'] = 'Welcome to this site';
$data['mytext'] = "Hello, $name, now we're getting dynamic!";
$this->load->view('testview', $data);
}
}
?>
视图:CI/application/views/testview.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Web test Site</title>
<base href="<?php echo base_url();?>" />
<link rel='stylesheet' type='text/css' href='<?php echo base_url("css/mystyles.css");?>' media='all'/>
</head>
<body>
<h1><?php echo $mytitle; ?> </h1>
<p class="test" > <?php echo $mytext; ?> </p>
</body>
</html>
结果:
chrome浏览器始终显示不出来效果
console控制台提示:Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/CI/index.php/start/hello/localhost/CI/localhost/CI/css/mystyles.css".
网页源码显示路径为:<link rel="stylesheet" type="text/css" href="http:localhost/CI/css/mystyles.css" media="all">
截图给大家看看,不明白是没找到CSS文件,还是找到了无法解析。不知道问题在哪。
|
|