CodeIgniter Forums
Confounded with CSS file!!! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Confounded with CSS file!!! (/thread-24953.html)



Confounded with CSS file!!! - El Forum - 11-25-2009

[eluser]puddles[/eluser]
I've done a lot of reading of posts in this forum on how to locate your css file, and have tried each method. For the life of me, I can't seem to get it working though!

Here is the location of my css file which I would like to call in a header view:

xampp
-> htdocs
-> codeigniter
-> system
-> assets
-> css
-> screen.css

Here is my base url from my config.php:

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

Here is my controller code
Code:
<?php

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {    
        
        $this->load->view('header');
        $this->load->view('welcome_message');
        $this->load->view('footer');
    }
}


Here is my header view:
Code:
<html>

<head>
<title>Welcome to Hockeypool Headquarters</title>

<style type="text/css">

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


</style>
</head>

No matter what I seem to do, I'm not able to get the css to apply to the welcome_message.php page.

When I look at the rendered page source, I see the following in the head section:

Code:
<style type="text/css">

    <link  href="http://localhost/codeigniter/assets/css/screen.css" rel="stylesheet" type="text/css" />

</style>



Can anyone point out where I've gone wrong?


Confounded with CSS file!!! - El Forum - 11-25-2009

[eluser]John_Betong[/eluser]
 
 
Try:
Quote: // config.php
$config['base_url'] = "http://localhost/";

// header view
<?php echo base_url(); ?>'assets/css/screen.css'

// if the above link is not valid then echo base_url() and adjust the path.
 
 
edit: changed path
 


Confounded with CSS file!!! - El Forum - 11-25-2009

[eluser]puddles[/eluser]
I tried your changes, but it did not work.

If the $config['base_url'] = "http://localhost/codeigniter/"; does it not correspond to this directory in my drive?

D:/xampp/htdocs/codeigniter/

If that is the case, and I have placed my css files in the following directory:

D:/xampp/htdocs/codeigniter/assets/css/

then shouldn't the rendered link, as follows, be correct?

<link href="http://localhost/codeigniter/assets/css/screen.css" rel="stylesheet" type="text/css" />

But it still the css files do not seem to take effect. I feel like I'm missing something very simple.


Confounded with CSS file!!! - El Forum - 11-25-2009

[eluser]khagendra[/eluser]
Your base_url is ok.
Inside <head></head> tag use like this.

Code:
<link href="<?=base_url()?>assets/css/screen.css" rel="stylesheet" type="text/css" />

Your problem will be solved.


Confounded with CSS file!!! - El Forum - 11-26-2009

[eluser]Aken[/eluser]
Actual file URLs are different than CodeIgniter Controller URLs. Your CSS and related assets are still physically located in the system folder, according to your example. Your code is fine, you're just not including the full location.

Code:
<?php echo link_tag('system/assets/css/screen.css'); ?>



Confounded with CSS file!!! - El Forum - 11-26-2009

[eluser]puddles[/eluser]
Thanks.....that works.


Confounded with CSS file!!! - El Forum - 11-27-2009

[eluser]gh0st[/eluser]
I don't put my assets in the system folder. I put it outside of CI altogether and keep it seperate.

ie:
/assets/css/
/assets/js/
/assets/images/
..etc
/system/

Then I make sure in the <head> of any document I put:

Code:
<link rel="/assets/css/whatever.css" />
<base href="<?=base_url();?>" />

This seems to work fine.


Confounded with CSS file!!! - El Forum - 11-27-2009

[eluser]Aken[/eluser]
[quote author="gh0st" date="1259353904"]I don't put my assets in the system folder. I put it outside of CI altogether and keep it seperate.

ie:
/assets/css/
/assets/js/
/assets/images/
..etc
/system/

Then I make sure in the <head> of any document I put:

Code:
<link rel="/assets/css/whatever.css" />
<base href="<?=base_url();?>" />

This seems to work fine.[/quote]
In most situations, with this file structure, you wouldn't even need the base HREF defined. But it doesn't hurt.