Header Menu; Importing/Reference from CSS or other files

r3faat1

New Member
So I am building a website and my header menu looks like this:

Code:
<ul class="hmenu">
<a href="./index.html" class="active">Home</a>
<a href="./guides_index.html">Guides</a>
<ul><a href="./guides/make-windows7-faster.html">Windows 7</a> 
      <a href="./guides/make-linux-faster.html">Linux</a>
      <a href="./programs_index.html">Programs</a>
</ul>

I would like to put that code into another file and be able to load it using only one line.

For example: Let's say I saved that code a file called hmenu.css (or whatever i should be using)

Can I load it using something like this ?
<link rel="stylesheet" href="hmenu.css" type="text/css"/>

How should this be done ? Any help or tips is greatly appreciated.
Thank you
 

CaldwellYSR

Member
two things.... one... your unordered list has no list items... that's a problem. Try...

HTML:
<ul>
    <li><a href="#">Item 1</a></li>
    <li><a href="#">Item 2</a></li>
    ...
</ul>

Then if you want to load that using one file start looking into the php include method. For example you could have a file called header which looks like...

HTML:
<!DOCTYPE html>
<html>
<head>
    <title>Page title</title>
    <!-- Other stuff like css links -->
</head>
<body>
    <ul>
        <li><a href="#">Item 1</a></li>
        <li><a href="#">Item 2</a></li>
        <li><a href="#">Item 1</a></li>
    </ul>

Which is named header.php then in your index.php all you have to call is...

PHP:
<?php include("header.php"); ?>

Assuming they're in the same directory. You should look into setting up php on your local machine though because this won't just run out of the box.
 
Top