Welcome Guest, Not a member yet? Register   Sign In
CSS not applying for controllers with 3+ URI segments in URL?
#1

[eluser]inktri[/eluser]
For example, I've got a controller called "user". Accessing:
http://localhost/user/bob/three
loads the page correctly HOWEVER the CSS doesn't apply


I handle the user view page with a "master view".

Code:
$this->load->view('header', $data);
$this->load->view($view);
$this->load->view('footer');

CSS style sheet is declared in the header view and it's located in /var/www/css/
Code:
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" />

Anyone know why the CSS isn't applying?
#2

[eluser]Popcorn[/eluser]
Use

Code:
<link rel="stylesheet" href="<?php echo base_url() ?>/style.css" type="text/css" media="screen" />

Instead. Make sure you have the URL helper loaded.
#3

[eluser]inktri[/eluser]
thanks, worked
#4

[eluser]CI Lee[/eluser]
Do you understand why it was broken?

-Lee
#5

[eluser]compoundeye[/eluser]
i'm guessing because you used a relative path to your css file:

../css/style.css

that when you start adding segments,

http://localhost/user/bob/three

it is interpreted as folders perhaps? so maybe its looking for

http://localhost/user/bob/css/style.css

instead of

http://localhost/css/style.css?

just a guess, if you really wanted to know you could create

http://localhost/user/bob/css/style.css
and
http://localhost/user/css/style.css
etc

to see what effect it has

cheers

mat
#6

[eluser]Colin Williams[/eluser]
It might help to study some of these basics before diving into actual development.




Theme © iAndrew 2016 - Forum software by © MyBB