0

The problem is that my CSS is not loading.

I have a folder /var/www/example, and in it i have my index.php and another folder assets where i have the folder /css

in my index.php i linked the css like this :

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

But when i put style.css in /var/www/example with index.php and i change my code to href="style.css it works !!

im working with Apache2

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • You are using a root relative path to the CSS file and presumably `/example` is a root folder so you would need `/example/assets/css/style.css` or you can try `href="assets/css/style.css"` if you want to link the CSS file relative to the location of the index page – MonkeyZeus Feb 07 '20 at 17:23
  • @MonkeyZeus i tried this, i still have the same problem –  Feb 07 '20 at 17:32
  • What is the URL to your `index.php` file? Is it `http://localhost/example/index.php`? – MonkeyZeus Feb 07 '20 at 17:33
  • Also, what is the full path to your CSS file? – MonkeyZeus Feb 07 '20 at 17:35
  • @MonkeyZeus when i enter http://localhost/example/index.php i have page not found, but when i enter localhost/ i have my index.php –  Feb 07 '20 at 17:35
  • @MonkeyZeus it's : /var/www/example/assets/css –  Feb 07 '20 at 17:36
  • What error do you get in your browser's Network console? – MonkeyZeus Feb 07 '20 at 17:37
  • @MonkeyZeus when i enter localhost/example/index.php i have: Not Found The requested URL was not found on this server. Apache/2.4.29 (Ubuntu) Server at localhost Port 80 –  Feb 07 '20 at 17:39
  • @MonkeyZeus and when i enter localhost/ my index.php is loaded but without the css –  Feb 07 '20 at 17:39
  • What you visit localhost, what error does your network console tell you about the CSS file? – MonkeyZeus Feb 07 '20 at 17:40
  • i don't have any errors there's just no css loading –  Feb 07 '20 at 17:42
  • i thought maybe it's something with apache2 server block but i dont know –  Feb 07 '20 at 17:45

1 Answers1

-1

The root directory is example so you have to put /example before assets the link should be like the example below, Another idea is to remove the / before assets as it is not the root directory (i.e it is directory) of the index.php file.

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