Welcome Guest, Not a member yet? Register   Sign In
Confounded with CSS file!!!
#1

[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?
#2

[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
 
#3

[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.
#4

[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.
#5

[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'); ?>
#6

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

[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.
#8

[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.




Theme © iAndrew 2016 - Forum software by © MyBB