![]() |
Site can not get CSS file - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Site can not get CSS file (/showthread.php?tid=50727) |
Site can not get CSS file - El Forum - 04-05-2012 [eluser]StevenTen[/eluser] Hi everyone, I'm trying to run my code on localhost, and I config it like this: Code: $config['base_url']='http://localhost:8080/' In my html file, I add css like this: Code: <link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style.css"> But when I run the site, it will display without css style But inside the web, the url is successfully linked. For example: Code: href="<?php echo base_url();?>user/login" But why can not find css file?? Site can not get CSS file - El Forum - 04-05-2012 [eluser]jzmwebdevelopement[/eluser] Do you get any errors? What localhost programme are you using? Site can not get CSS file - El Forum - 04-05-2012 [eluser]skunkbad[/eluser] If using a base tag try: Code: <base href="<?php echo base_url(); ?>" /> If not using a base tag, try: Code: <link rel="stylesheet" type="text/css" href="/css/style.css"> You could also use codeigniter's link_tag(), which I believe is in the html helper: Code: echo link_tag( array( 'href' => 'css/style.css', 'media' => 'screen', 'rel' => 'stylesheet' ) ); And I believe the proper way to use the base_url is like this: Code: <link rel="stylesheet" type="text/css" href="<?php echo base_url('css/style.css'); ?>"> Site can not get CSS file - El Forum - 04-06-2012 [eluser]Aken[/eluser] I cannot believe how many people are trying to program PHP, but CANNOT fix this extremely simple problem. Site can not get CSS file - El Forum - 04-06-2012 [eluser]skunkbad[/eluser] [quote author="Aken" date="1333767925"]I cannot believe how many people are trying to program PHP, but CANNOT fix this extremely simple problem.[/quote] This statement would be appropriate for 50% of the questions asked in this forum. Site can not get CSS file - El Forum - 04-06-2012 [eluser]Aken[/eluser] Ain't that the truth... Site can not get CSS file - El Forum - 04-06-2012 [eluser]InsiteFX[/eluser] His base_url is wrong! He's not showing any directory where CI is installed... Site can not get CSS file - El Forum - 04-06-2012 [eluser]skunkbad[/eluser] [quote author="InsiteFX" date="1333773003"]His base_url is wrong! He's not showing any directory where CI is installed... [/quote] Maybe the website is in public root, and not in a subdir? Site can not get CSS file - El Forum - 04-07-2012 [eluser]StevenTen[/eluser] Thanks skunkbad, this works fine now! [quote author="skunkbad" date="1333692816"]If using a base tag try: Code: <base href="<?php echo base_url(); ?>" /> If not using a base tag, try: Code: <link rel="stylesheet" type="text/css" href="/css/style.css"> You could also use codeigniter's link_tag(), which I believe is in the html helper: Code: echo link_tag( array( 'href' => 'css/style.css', 'media' => 'screen', 'rel' => 'stylesheet' ) ); And I believe the proper way to use the base_url is like this: Code: <link rel="stylesheet" type="text/css" href="<?php echo base_url('css/style.css'); ?>"> |