Welcome Guest, Not a member yet? Register   Sign In
how to insert a css on codeingiter
#1

[eluser]Unknown[/eluser]
Hi all, I'm Steven and is a first to approacing a codeigniter. I have a problem to insert a external css in to a file php, I create a file css and i wirite a code for recall him (<link rel="stylesheet" href='css/style.css' type="text/css" media="screen" /&gtWink but codeingiter dont' load the css style.

I'm looking more topic to recall the css but more topic speaking for a file .htaccess for resolve this problem.

Can you help me?

Thank you guys.
#2

[eluser]adamp1[/eluser]
CodeIgniter has nothing to do with the CSS. Your css files will be handled in the html. The example you gave there is using a relative URL, have you tried an absolute url instead?
#3

[eluser]Unknown[/eluser]
Today I try. thank you.
#4

[eluser]Mischievous[/eluser]
Welcome to CodeIgniter community Stelab!

If your CSS is located anywhere inside your site root you must specify where its located in your .htaccess file

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|templates|media|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]

*Note: look at the last part of the second line of code "|css" should be where ever your css is located or if you put it in your root it should be your "|css\.css"

Also when loading your css in a view be sure to load up the url helper and run <?=base_url()?> to get your absolute path incase you change the base url in your config file you dont have to go through all your view files to change! Wink
#5

[eluser]evolutionxbox[/eluser]
You could also try:
Code:
<link rel=“stylesheet” href=‘<?=base_url()?>css/style.css’ type=“text/css” media=“screen” />)
#6

[eluser]tanero[/eluser]
Your base url value in your application/config/config.php file.

Also , css , image and other public materials must be in your public webroot.

When you setup your view file base_url() will show your public root. Codeigniter will not access directly. Your rendered html will access it.
#7

[eluser]matula[/eluser]
Is there anyway to access the CSS through CI if the CSS directory is in the 'application' directory? In my case, I have the application dir outside of the system dir, and then in Eclipse, I'm using the application dir as my project folder. When I put the CSS dir in the root, it works fine... but I'm not able to access/edit it directly in Eclipse.

It could be an htaccess issue, but I'm not versed enough to know how to change it.

Any thoughts? Thanks.
#8

[eluser]Mischievous[/eluser]
Hey Metula use this ->

RewriteCond $1 !^(index\.php|templates|media|robots\.txt|css|system/application/css)

when you want to allow access to a folder or file simply add another " | " and then type your directory in. If your trying to allow access to a file escape the dot with a backslash.
#9

[eluser]matula[/eluser]
perfect... thanks!
#10

[eluser]tanero[/eluser]
[quote author="Mischievous" date="1270677977"]Hey Metula use this ->

RewriteCond $1 !^(index\.php|templates|media|robots\.txt|css|system/application/css)

when you want to allow access to a folder or file simply add another " | " and then type your directory in. If your trying to allow access to a file escape the dot with a backslash.[/quote]

Warning , it is not a good habit to let system and apllication directories be accessible from public.

This is a securtiy warning.




Theme © iAndrew 2016 - Forum software by © MyBB