Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

php - How to load css in codeigniter

I am new to codeigniter, and I am using v.2.12. I am getting an error when I try to load the css from the external file.

I create the css folder inside the application folder. And I create the css file in the name of all.css.

In the view file I use the following code to link the css file.

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

But the css file is not loading. I'm getting 404 error. Here is my configuration settings:

$config['base_url'] = 'http://webscarlets.com/ci/index.php';
$config['index_page'] = 'index.php';

Website Link: http://webscarlets.com/ci/index.php/welcome.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is how you include CSS files in CodeIgniter:

<?php echo link_tag('css/mystyles.css'); ?>

That snippet will output this HTML:

<link href="http://site.com/css/mystyles.css" rel="stylesheet" type="text/css" />

The function link_tag is in the HTML helper, which must first be loaded.

(Note that you probably shouldn't put your CSS files in /application/css. It's just easier to put them in /css or maybe /assets/css.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...