Welcome Guest, Not a member yet? Register   Sign In
How to create a default css file for CI?
#1

[eluser]Shaheer[/eluser]
Hello, this is my first day at CI. i was creating a sample page and i succeed. But when i tried to add a css file it failed. I put the same css file in Views folder and System and main htdocs but it just didn't got attached. Can any one help?

Sorry for my English
#2

[eluser]tomcode[/eluser]
Welcome to CI Wink.

Using CI You should always use absolute URL's for assets( CSS, images, links), since depending on Your controller the page URL changes.

There are several possibilities, read the user guide.


In Your case use base_url() from either the url helper or the config class.
#3

[eluser]Shaheer[/eluser]
thanks for reply.

can you post the link to that page of user guide. i haven't covered CI completely yet i am using a book. so i didn't yet understand about that base_url thing. Please help.
#4

[eluser]tomcode[/eluser]
http://ellislab.com/codeigniter/user-gui...elper.html

http://ellislab.com/codeigniter/user-gui...onfig.html, fetching config items
#5

[eluser]Slowcheetah[/eluser]
i use

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

And place my css:
codigniter_installation/assets/css/master.css
#6

[eluser]tomcode[/eluser]
Where do You have You index.php ?

webroot/index.php
webroot/codigniter_installation/index.php

The base_url always starts where Your index.php is.
#7

[eluser]Shaheer[/eluser]
it still doesn't work i have placed the style.css file in the same folder as index.php but no changes Sad
below is the view file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;link rel="stylesheet" href="&lt;?php echo base_url(); ?&gt;style.css" /&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Web Test Site&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<h1>&lt;?php echo $mytitle; ?&gt;</h1>
<p class="test"> &lt;?php echo $mytext; ?&gt; </p>
&lt;?php echo $base ?&gt;
&lt;/body&gt;
&lt;/html&gt;

$base and other vars are passed by control.
#8

[eluser]Slowcheetah[/eluser]
What output has the folowing code?

Code:
&lt;?php echo base_url(); ?&gt;
#9

[eluser]tomcode[/eluser]
Check the resulting HTML code ...
#10

[eluser]Shaheer[/eluser]
first it was

http://www.example.com/ then i modified it to http://localhost.

is the problem with that?




Theme © iAndrew 2016 - Forum software by © MyBB