0

I'm confuse. echo is use when you want to show that to front. but I guess importing css file url is not need for show to front because you just refer to location of url.


Sometimes, import css without echo, it's work fine.

<link rel="stylesheet" type="text/css" href="<?php base_url();?>css/animate.css"> 

but sometimes If I did not use echo, it will not work.

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

What's this meaning?

1 Answer 1

2

base_url calls a function, echo in front means display the output of the function.

I believe that the reason why it works "sometimes" is because the file that works is on the same level as the css folder itself. Meaning your index.php will work, however going to {somefolder}/somefile.php wont work, as that too will look for its own css folder, inside {somefolder}.

Generally what I do is place a slash infront of the path itself, that eliminate the need to use a function to begin with, and it also means that no matter how many sub-folders you may have it will always load the same style.css file.

<link rel="stylesheet" type="text/css" href="/css/style.css"> 

Using that will guarantee it works on all pages you may have, taken you have a css folder in the public_html folder, or website root directory.

Sign up to request clarification or add additional context in comments.

3 Comments

I forgot tell you if I use echo it guarantee work too.
Are you sure that absolute path guarantees style will be loaded?
100% sure, I always place the css folder in the root, and simply use a slash. Works every time.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.