如何在 xampp 开发环境中使 css 加载到 CodeIgniter 中


How do I make the css load in CodeIgniter in an xampp development environment?

我正在使用xampp在我的Windows机器上设置一个本地CodeIgniter开发环境。我在使用css文件时遇到了一些麻烦。我猜我需要在某处配置应用程序的路径。

开发网址是这个(这是路由到主页(:

localhost/my_app

我像这样链接我的样式表

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

在生产服务器上,这工作得很好,但是CSS不会在本地加载,因为它似乎链接到localhost/css/style.css而不是localhost/my_app/css/style.css

当我将链接更改为此链接时,它可以工作:

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

此链接有效,但仍然无法加载我正在使用的background-image:url('/images/image.png')

我不想用my_app/directory_i_want_to_access编写所有路径的代码,因为这样我就必须在推送到生产环境时返回并更改它们。

尝试:

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

对于 CSS 中的图像链接,假设这是您的文件夹结构

/ Assets
| - /images
| - | - image.png
| - /css
| - | - / style.css

只需链接到相对于CSS文件的图像,因此在这种情况下,它将../images/image.png

<base href="<?php echo base_url(); ?>">

添加您的HTML文件,您的链接现在应该可以工作了。

由菲尔·斯特金提供