简体   繁体   中英

stylesheet not working with codeigniter

I am new to codeigniter.I have created style sheet called mystyle.css with a folder structure of application/styles/mystyle.css .My view is first_view.php with a folder structure of application/views/first_view.php .I have placed the href link like this:

file:///C|/wamp/www/demo_code/application/styles/mystyle.css.

It doesnt work,but it displays the contents with no style.When i use like this

href="<?php echo base_url('styles/mystyle.css');?>" 

the age is displayed with no contents.I didnt understand how this happens.Please help me

EDIT

My config file contains like this:

$config['base_url'] = '';
$config['index_page'] = 'index.php';

I first advice u that it is recommended that store your css in assets

/www
/code_igniter
    /application
    /assets
        +img
        +css
        +js
    /controllers
    /system

then use it in your view as including it

<link type="text/css" rel="stylesheet" href='<?echo base_url()?>assets/css/mystyle.css'>

into your .htacess file add this

  RewriteEngine on
  RewriteCond $1 !^(index\.php|assets|_searches|robots\.txt|favicon\.ico)
  RewriteRule ^(.*)$ /sample/index.php/$1 [L]

also include this assests folder into your .htaccess file

It is important to understand, that CSS is purely client-side, this has nothing to do with CodeIgniter. CodeIgniter generates HTML, which is parsed by the clients browser.

The HTML tag

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

instructs your browser to download a separate stylesheet file /css/format.css which is fetched from the webserver in a seperate request .

Your webserver delivers this file, note that the path for all files requested from a webserver is relative to your webservers configured document root.

../application/.. does not look like a folder in document root. The folder is usually called htdocs or public or httpdocs. I think codeigniter is working with a central index.php where all dynamic requests are redirected to. Static files have to be in the same folder or below.

使用此代码集成样式表

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

Change this line by this in confing file

$config['base_url'] = 'http://localhost/your_project_name/';

if you are running your site on local server then do nothing if your have running on other server then type its name (domain name) and replace with localhost .

At first change your folder structure to

 /public/css/mystyle.css (optional)

To include a stylesheet you can do this at

 <head> tag:

as

<LINK href= "<?=site_url(); ?>public/css/mystyle.css" rel="stylesheet" type="text/css">

if doesn't work you must configure your .htaccess

Put the stylesheet, js or other resource outside the application folder. it is standard and secure. Use this line to include css or js.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM