我在 codeigniter 中有一个名为 Home 的 Controller ,代码如下所示:
class Home extends CI_Controller {
public function index() {
$this->load->view('foundation_css');
$this->load->view('topbar');
$this->load->view('home_page');
}
}
foundation_css View 包含链接的基础 css,topbar View 包含显示顶部栏的 html,home_page View 构建基本主页。
这是当我访问的 url 是 http://localhost/codeigniter/index.php
时页面的样子.
这是当我访问的 url 是 http://localhost/codeigniter/index.php/home/
时页面的样子.
为什么 url 改变时 CSS 消失了?我访问 css 文件的 url 是否发生变化?如果是这样,我将如何补救这种情况?有关更多信息,我使用的网址是 <link rel="stylesheet" type="text/css" href="css/foundation.min.css">
.文件树看起来是这样的:
/
css/
-foundation.min.css
application/
controllers/
home.php
views/
foundation_css.php
topbar.php
home_page.php
最佳答案
对 css 文件使用完整链接。
<link rel="stylesheet" type="text/css" href="<?=base_url();?>path_to_css_folder/css/foundation.min.css">
主要是因为当你把url改成/home/的时候,它就像server的子目录,他找不到你的css文件夹。
关于php - Codeigniter css 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22722458/