0

I have a index.php file on my root folder and it has an header file included like

include 'include/header.php';

In that header.php i have following code at start...

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<title>title</title>
<link rel="stylesheet" href="./css/main.css" type="text/css" />
<link rel="stylesheet" href="./css/dashboard.css" type="text/css" />
<script src="/js/jquery-1.10.2.js"></script>
<script src="/js/bootstrap.js"></script>
<script src="/js/tablesorter/jquery.tablesorter.js"></script>
<script src="/js/tablesorter/tables.js"></script>
</head>
<body>

The above index.php is working fine on root folder but when i use it in other folder it then css is not working for same file... if i use abc/index.php then css will not work for that file...

Note : I have used ./ as well as / or nothing at all but its not working.

4
  • 1
    What is your directory structure? Where are the css files kept? Commented Jun 21, 2014 at 6:03
  • 1
    use your full path with your css and js files Commented Jun 21, 2014 at 6:05
  • is the first / in /css/main.css" really necessary? maybe just "css/main.css" Commented Jun 21, 2014 at 6:05
  • @NerdByDesign you should understand what it means to have a leading slash. I highly suggest to always use a leading slash and use the full path to the css/js files so you never have a problem from any directory structure. Commented Jun 21, 2014 at 6:07

2 Answers 2

2

You can use base tag and change your code like this

<base href="http://localhost/abc/" />

<link rel="stylesheet" href="css/main.css" type="text/css" />
<link rel="stylesheet" href="css/dashboard.css" type="text/css" />
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/tablesorter/jquery.tablesorter.js"></script>
<script src="js/tablesorter/tables.js"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

SOLVED..! Thank you very much Syam Mohan... You saved my work as adding that base tag is worked... All working fine.. Thanx Again...!
0

I don't know where the dir css is but you need to change all of these urls

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

to absolute ones:

 <link rel="stylesheet" href="/root/wherever/css/main.css" type="text/css" />

1 Comment

Thanx for reviewing my problem... Actually Syam Mohan's answer worked for me... Thanx to you also for your Valuable comment...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.