CodeIgniter - 链接外部css不工作 [英] CodeIgniter - Linking an exernal css not working
问题描述
这里是我的文件的层次结构
Codeigniter /
applications /
assets /
styles.css
...
views /
welcome.php
system /
...
在我的style.css下是此代码
p {
color:#3333ff;
background-color:#66ff66;
}
并且welcome.php下是这个。
<!DOCTYPE html>
< html lang =en>
< head>
< meta charset =utf-8>
< title> test< / title>
< link rel =stylesheettype =text / csshref =<?php echo base_url();?> assets / styles.css/>
< / head>
< body>
< p>测试< / p>
< / body>
< / html>
我将base_url设置为
$ config ['base_url'] ='http:// localhost / Codeigniter /';
我无法理解为什么css文件不起作用
我也尝试改变链接到
< link rel =stylesheettype =text / css href =<?php echo base_url();?> application / assets / styles.css/>
但不起作用
解决方案我有一个类似的本地设置(XAMPP),我有以下文件层次结构:
public_html_local /
applications /
assets /
css /
styles.css
...
js /
jquery.js
...
images /
banner.jpg
...
system /
...
在我的配置文件中:
$ config ['base_url'] =http:// localhost / public_html_local /
,在我的页面中,我访问我的CSS文件如下:
< base href =<?php echo base_url();?>>
< link href =assets / css / reset.css =stylesheet>
< link href =assets / css / styles.css =stylesheet>
对我来说,我发现更容易将我的CSS文件保存在应用程序文件夹之外。
在你的情况下,你可能希望你的CSS文件的路径是:
< link rel =stylesheettype =text / css
href =<?php echo base_url();?> applications / assets / styles.css/>
但是,如果您尝试使用
URI从本地服务器访问CSS文件,除非您更改了.htaccess
文件,否则它可能无法工作。Here is the hierarchy of my files
Codeigniter/ applications/ assets/ styles.css ... views/ welcome.php system/ ...
under my style.css is this code
p { color: #3333ff; background-color: #66ff66; }
and under the welcome.php is this one.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>test</title> <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>assets/styles.css" /> </head> <body> <p>test</p> </body> </html>
I set my base_url as
$config['base_url'] = 'http://localhost/Codeigniter/';
I cant understand why the css file isn't working
I also tried to change link to
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>application/assets/styles.css" />
but didn't work also
解决方案I have a similar local setup (XAMPP) and I have the the following file hierarchy:
public_html_local/ applications/ assets/ css/ styles.css ... js/ jquery.js ... images/ banner.jpg ... system/ ...
In my config file:
$config['base_url'] = "http://localhost/public_html_local/"
and in my pages, I access my CSS files as follows:
<base href="<?php echo base_url(); ?>"> <link href="assets/css/reset.css" rel="stylesheet"> <link href="assets/css/styles.css" rel="stylesheet">
For me, I found it easier to keep my CSS files outside of the application folder.
In your case, you might expect the path to your CSS files to be:
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>applications/assets/styles.css" />
However, if you try to access the CSS file from your local server using that URI, it probably won't work unless you changed the
.htaccess
file.这篇关于CodeIgniter - 链接外部css不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!