简体   繁体   中英

css not working when header.php file included in other than root folder but working on root folder

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.

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>

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" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM