CodeIgniter Forums
Cannot load CSS, loads inside HTML tags - 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: Cannot load CSS, loads inside HTML tags (/showthread.php?tid=54320)

Pages: 1 2


Cannot load CSS, loads inside HTML tags - El Forum - 09-03-2012

[eluser]Stergios[/eluser]
Hi all,

I'm new to CI although I have a decent knowledge of php. So my first problem is that I cannot load the CSS files. I have created an assets folder (where I intend to save css, js etc) outside the application folder. I've tried everything I found on internet about the problem but I still can't fix it.

If I view the source code through the browser, I see that the link to the CSS file is correct, however if I click on it I get this :

Code:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
&lt;html&gt;&lt;head>
&lt;title&gt;404 Not Found&lt;/title&gt;
&lt;/head&gt;&lt;body>
<h1>Not Found</h1>
<p>The requested URL /codeigniter/assets/css/basicLayout2.css was not found on this server.</p>
&lt;/body&gt;&lt;/html>

I've tried many things on .htaccess (I have no knowledge of apache but I've copied everything I found on google). Nothing seems to work. It's the 2nd day now and I'm losing my patience. Please help. Thank you !!


Cannot load CSS, loads inside HTML tags - El Forum - 09-03-2012

[eluser]Unknown[/eluser]
My young boy. Show us how you are calling the CSS from your view.

Normally I do this:
Code:
&lt;link href="&lt;?php echo site_url('public/css/default.css'); ?&gt;" type="text/css" rel="stylesheet"&gt;



Cannot load CSS, loads inside HTML tags - El Forum - 09-03-2012

[eluser]Stergios[/eluser]
Well I've used every way I found on web like:

Code:
&lt;?php echo css('basicLayout2.css');
echo link_tag('assets/css/basicLayout2.css'); ?&gt;

or

Code:
&lt;link rel=stylesheet href="&lt;?php echo base_url(); ?&gt;assets/css/basicLayout2.css" type=text/css/&gt;

or

Code:
&lt;link rel="stylesheet" href="http://localhost/codeigniter/assets/css/basicLayout2.css" type="text/css" media="screen, projection" /&gt;

or

Code:
&lt;link rel="stylesheet" href="assets/css/basicLayout2.css" type="text/css" media="screen" /&gt;



Cannot load CSS, loads inside HTML tags - El Forum - 09-03-2012

[eluser]vitoco[/eluser]
Are you using .htaccess to eliminate index.php? if so, show us that also.


Cannot load CSS, loads inside HTML tags - El Forum - 09-03-2012

[eluser]TWP Marketing[/eluser]
And is the link statements place within the &lt; head&gt;...< /head> tags, which is where they should be or in the view body?


Cannot load CSS, loads inside HTML tags - El Forum - 09-04-2012

[eluser]Stergios[/eluser]
@vitoco I've tried using .htaccess but I've also tried without modifying it. So the problem isn't (?) there.

@TWP Yes the link statements are within &lt;head&gt;

What could I try?


Cannot load CSS, loads inside HTML tags - El Forum - 09-04-2012

[eluser]Stergios[/eluser]
Moreover, if in my code I use this

Code:
&lt;link rel="stylesheet" href="http://localhost/codeigniter/index.php/assets/css/basicLayout2.css" type="text/css" media="screen, projection" /&gt;

and then I click on it through the source code of the browser, I get this:

Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;404 Page Not Found&lt;/title&gt;
&lt;style type="text/css"&gt;

::selection{ background-color: #E13300; color: white; }
::moz-selection{ background-color: #E13300; color: white; }
::webkit-selection{ background-color: #E13300; color: white; }

body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
}

a {
color: #003399;
background-color: transparent;
font-weight: normal;
}

etc.......


&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
<div id="container">
  <h1>404 Page Not Found</h1>
  <p>The page you requested was not found.</p> </div>
&lt;/body&gt;
&lt;/html&gt;



Cannot load CSS, loads inside HTML tags - El Forum - 09-04-2012

[eluser]TWP Marketing[/eluser]
Check the access permissions on the css file itself.
I assume you have other assets in the same assets folder? Which work as expected?
Check permissions on each level of the asset tree to be sure you have access permission.


Cannot load CSS, loads inside HTML tags - El Forum - 09-04-2012

[eluser]Stergios[/eluser]
I have some other assets (images) but they don't work either. The permission give 'read' access to all users.


Cannot load CSS, loads inside HTML tags - El Forum - 09-04-2012

[eluser]TWP Marketing[/eluser]
[quote author="Stergios" date="1346776355"]Moreover, if in my code I use this

Code:
&lt;link rel="stylesheet" href="http://localhost/codeigniter/index.php/assets/css/basicLayout2.css" type="text/css" media="screen, projection" /&gt;

and then I click on it through the source code of the browser, I get this:

Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;404 Page Not Found&lt;/title&gt;
&lt;style type="text/css"&gt;

::selection{ background-color: #E13300; color: white; }
::moz-selection{ background-color: #E13300; color: white; }
::webkit-selection{ background-color: #E13300; color: white; }

body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
}

a {
color: #003399;
background-color: transparent;
font-weight: normal;
}

etc.......


&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
<div id="container">
  <h1>404 Page Not Found</h1>
  <p>The page you requested was not found.</p> </div>
&lt;/body&gt;
&lt;/html&gt;
[/quote]
The page you are seeing is not your page, it is the 404 error page, which, of course, will not have your css code in it.
The error says that the server cannot locate your view.
We need to step back to your controller and see which page is being loaded to the browser. Can you show us the controller code which contains your load statement? My code would be something like this:
Code:
$this->load->view('mypage');
if you are using CI's system