How to load CSS into CodeIgniter


Tags: css,codeigniter

Problem :

I am totally new in CodeIgnitor. In the controllers folder I created a file named caller.php and I created a file home.php in views. In views I also created a folder named css and I created style.css in that css folder. In views I have some pictures. Those pictures are also part of design. Now I want to use style.css and the pictures. But I can't.

In caller.php I have:

class caller extends CI_Controller
{
    function index()
    {

        $this->load->view('home');  
        // What do I have to write here to load css?
    }
}

In home.php I have:

<html>
<head>

***------what i have to write here to load css--------***

</head>

<body>

<div id="outer">
...
</div>

</body>

</html>

If additional configs are needed please mention that.



Solution :

Leading on from what Oliver said of including the stylesheet with:

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

If you have removed index.php from your URL's make sure you include your css directory in the rewrite rule.

RewriteEngine on
RewriteCond $1 !^(index\.php|css)
RewriteRule ^(.*)$ /index.php/$1 [L]

This is assuming your stylesheet is located in a folder called css at the root of your application.

- index.php
+ system
+ application
+ css
   - style.css

Make sure that you have enabled the URL helper to use commands such as base_url(). This can be done globally inside config/autoload.php by adding url to the helper array.

$autoload['helper'] = array('url');

    CSS Howto..

    How to align the menu to center after certain width media query fires for RWD

    Css Tricks - How to align 4 div's

    How to make image scale as per browser window?

    How to place Facebook send dialog box above other content?

    Css code how to create multiple div classes

    How to fill remaining height and width?

    How to place several elements in one row when using a list?

    How to use bootstrap to hide one of div when zoom browser windows size smaller

    How to manage multiple css files in rails 4?

    How to reset the style properties to their CSS defaults in javascript?

    how to change other element css when selected element has new class

    How to create CSS/JavaScript circles grid

    How to make text “Passed” and progress bar appear in line in smaller views?

    How to trigger one element inside a div on mouse hover in CSS

    list-style-type no showing

    Show text-decoration when hover over div

    How to set a image over another in the same tag via CSS?

    How can I figure out how much a div shifts when a translate:scale is applied?

    How can you assign a class to an id in css or javascript?

    How to fit a big picture in a smaller space

    hide/show element with add/removeClass with CSS transition

    How to scale SVG properly and responsively in HTML5?

    How to put css class in to html:select element in jsp

    How to position a background image in reveal.js?

    How to set my span text vertical align and next to my image?

    How to make CSS background-image responsive? [duplicate]

    How to add multiple CSS elements to a div using jQuery?

    How to change the style of horizontal menu

    How to hide first level span element by CSS “>” selector

    How to make a button with image inside?