[英]Codeigniter CSS not being applied to html view pages
The css is not being applied to the html views in my codeigniter project. css未应用于我的codeigniter项目中的html视图。 Everything else seems to be working fine.
其他一切似乎都运转良好。
One answer on StackOverflow suggested removing the ?= base_url() ? StackOverflow上的一个答案建议删除?= base_url()? part , which I Have tried but that doesn't work either,
部分,我尝试过,但也不起作用,
This is the head.php file in templates, which contains the css. 这是模板中的head.php文件,其中包含css。
Where else could the problem lie? 还有什么地方可以解决问题?
<head>
<?php require_once("meta.php"); ?>
<title><?= $title ?></title>
<link rel="shortcut icon" href="<?= base_url() ?>resource/images/favicon.ico" type="image/x-icon" />
<link href="<?= base_url() ?>resource/css/bootstrap.min.css" rel="stylesheet" />
<link href="<?= base_url() ?>resource/css/modern-business.css" rel="stylesheet" />
<link href="<?= base_url() ?>resource/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="<?= base_url() ?>resource/css/animate.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
I have tried removing the base part, but that doesn't work either. 我试过删除基本部分,但这也不起作用。
<head>
<?php require_once("meta.php"); ?>
<title><?= $title ?></title>
<link rel="shortcut icon" href="<?= base_url() ?>resource/images/favicon.ico" type="image/x-icon" />
<link href="resource/css/bootstrap.min.css" rel="stylesheet" />
<link href="resource/css/modern-business.css" rel="stylesheet" />
<link href="resource/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="resource/css/animate.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
You have to recheck your configs and make sure you set your base_url
correctly in your config.php
so it would be something like that: 你必须重新检查你的配置,并确保你在
config.php
正确设置base_url
所以它会是这样的:
$config['base_url'] = 'http://localhost/YOUR_PROJECT_DIRECTORY/';
enable mod_rewrite
and make sure your .htaccess
is in your FCPATH
and is as simple as this: 启用
mod_rewrite
并确保你的.htaccess
在你的FCPATH
并且就像这样简单:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
finally remove your index.php
in your config.php
if you are not using it like this: 如果你不是这样使用它,最后在你的
config.php
删除你的index.php
:
$config['index_page'] = '';
and your ready to go, load the url_helper
in your controller: 并准备好了,在你的控制器中加载
url_helper
:
$this->load->helper(['url']);
now you can use base_url
correctly wherever you want: 现在您可以在任何地方正确使用
base_url
:
<link href="<?= base_url('resource/css/bootstrap.min.css') ?>" rel="stylesheet" />
Just make sure that this path is correct and inspect>console
in your browser to see if it is loaded. 只需确保此路径正确并在浏览器中
inspect>console
以查看它是否已加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.