gpt4 book ai didi

CSS 未加载

转载 作者:太空宇宙 更新时间:2023-11-04 16:18:33 24 4
gpt4 key购买 nike

您好,我在加载 CSS 文件时遇到问题。

<?php  //if ( ! defined("BASEPATH")) exit("No direct script access allowed");


class Controller2 extends CI_Controller
{


function index()
{
if ($this->input->post('button'))
$this->test();
else
$this->load->view('2');
}



function test()
{
$this->load->view('2');
}

}?>

当我第一次调用我的 Controller 索引函数时,它正在加载带有正确 html 和 css 的 View “2”,但是当我在“2” View 中按下一个按钮时,我的 Controller 正在调用另一个函数 TEST,但这次测试没有加载与 css 相同的 View 。

谁能解决这个问题?

最佳答案

利用我的灵力,因为你提供的很少,我相信答案是你提供了一个指向你的 CSS 文件的相对路径。

在您看来,您需要确保绝对引用 CSS 文件。示例:

错误

<link rel="stylesheet" type="text/css" href="style.css" />

这只有在路径保持不变的情况下才有效。但是,您的路径正在从 /controller2 更改为 /controller2/test,这意味着在第二个页面上,浏览器将查找 /controller2/style .css 用于第一种方法,/controller2/test/style.css 用于第二种方法。

正确

<link rel="stylesheet" type="text/css" href="<?php echo site_url('style.css') ?>" />

现在,输出将是样式表的绝对路径。现在,无论页面如何,浏览器都会在同一个地方查看。

(如果这对您有效,请确保您选中复选标记以接受答案。然后返回并接受您之前问题的有效答案!)

关于CSS 未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7035302/

24 4 0
文章推荐: jquery - 重叠
文章推荐: css - 滚动条不显示
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com