1

I am new to codeigniter and trying to learn it but i am unable to load or use my css stylesheet for layout. The method i followed to load CSS file is what i found on internet but it did not worked. Please suggest something.

Here is my code:

<html>

<head>
<title>homePage</title>

 <!--[if lte IE 6]>
    <style type="text/css">
    img, div { behavior: url(http('<?php echo $base_url; ?>images') }
    </style>
<![endif]-->


<!--[IF lte IE 6]>

<link rel="stylesheet" href="<?php echo $base_url; ?>/css/homestyle.css" type="text/css" />

<![endif]-->
</head>

 <body >


 <div id="page">
 <div id="menulinks">
    <a class="active" href="#"><span>Home</span></a>
    <a href="#"><span>Services</span></a>
    <a href="#"><span>About Us</span></a>
    <a href="#"><span>Contact Us</span></a>
</div>
<div id="header">

</div>
          <div class="active" id="contentarea">
  <br>
 <br> 
 </div>

 </div>
</body>

</html>
3
  • 1
    Where did you place your css files? Commented Sep 29, 2012 at 16:29
  • my css files are in my www/codeiginitor/res/css/style.css Commented Sep 30, 2012 at 9:06
  • res folder and css folder are made by me and i placed my style sheet in it . and in view file i wrote like this. <link rel="stylesheet" href="res/css/homestyle.css" type="text/css" /> Commented Sep 30, 2012 at 9:07

2 Answers 2

2
<!--[IF lte IE 6]>
<link rel="stylesheet" href="<?php echo $base_url; ?>/css/homestyle.css" type="text/css" />
<![endif]-->

This is a comment and most browsers will not parse what is inside. It is usable only under IE. You need to put <link> outside the comments:

<link rel="stylesheet" href="<?php echo $base_url; ?>/css/homestyle.css" type="text/css" />
Sign up to request clarification or add additional context in comments.

7 Comments

i have written this tag like this now in my view file .. still it did not work . my css file is in : www/codeignitor/res/css/homestyle.css <link rel="stylesheet" href="res/css/homestyle.css" type="text/css" />
It must be something with the path. try with / at the beginning href="/res/css/homestyle.css"
now my css style is loaded but im not able to see my background images. my images are in css file. #header { width:900px; height:119px; background-image:url(/images/header.png); padding-top:70px; padding-bottom:8px; padding-right:-20px; } but they are not being loaded.. images folder is placed in www/codeignitor/images where i am wrong
image path must be relative to the css position. If css file is ww/codeignitor/res/css/ and images in ww/codeignitor/images that means the relative path from css files is ../../images/ and it should look like this: background-image:url(../../images/header.png);
i'm sorry i did not understand your point... could you plz elaborate?
|
1

HTML wrapped in <!--[if lte IE 6]> will only be parsed by IE6 and older - which is great for your behavior attribute, but probably to restrictive for homestyle.css. Try this:

 <head>
    <title>homePage</title>
    <base href="<?= $base_url;?>">
    <!--[if lte IE 6]>
        <style type="text/css">
            img, div {
                behavior: url(images);
            }
        </style>
    <![endif]-->
    <link rel="stylesheet" href="css/homestyle.css" type="text/css" />
</head>

Edit after your comments:

Well yea, I assumed you had that variable defined from your question. Head into config/autoload.php and add the 'url' key to the $autoload['helper'] array:

For example: $autoload['helper'] = array('url', 'file', 'your_other_helpers...');

Then change the above HTML to <base href="<?= site_url();?>">

1 Comment

i tried it but got this error .. A PHP Error was encountered Severity: Notice Message: Undefined variable: base_url Filename: core/Loader.php(829) : eval()'d code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.