-1

Once I have the nav bar designed with HTML and CSS elements... if I put the HTML in its own file, can I link to it some way in the other pages so that the nav bar shows up?

The CSS is in its own file already of course.

The HTML includes a list with the nav bar topics, plus the banner across the top of the page and some images. We want that same banner and nav bar on every page. (It's for a small non-profit group.)

In all the sites explaining how to create a nav bar, I have yet to see mention of this idea. It's like subroutines (except no variables passed).

Thanks. The problem was solved with the Include statement!

curls
  • 382
  • 1
  • 3
  • 16
  • 2
    You could learn to use PHP and use server side includes. Put the nav in its own file and just include it. – MarshallOfSound Sep 06 '15 at 22:40
  • 1
    @MarshallOfSound You're right. See my answer for that. – PeterPan Sep 06 '15 at 22:42
  • 2
    If you want to do this with pure HTML can use ``, but that may be not widely supported. The usual approach is to use a server-side application, like PHP, ASP etc. – Havenard Sep 06 '15 at 22:46
  • I don't see the answer in that question linked to. It's about frames and ajax and css. My question is more limited in scope. (I didn't see it in searches, but I'd be surprised if there aren't.) I'll stick with php if it's as simple as include statements. I'm unclear on the syntax and asked questions about that below in the next answer. – curls Sep 07 '15 at 00:09

1 Answers1

3

If I get you right, you can do the following with PHP:

include("header.html");

Just change header.html to the location your header is saved and insert the code in every page.

PeterPan
  • 684
  • 1
  • 10
  • 27
  • This sounds great. Now I need to understand it. I have one php file for this site that's called from an input form. To do this -- which files with html are renamed to .php? The header file is html in your clause. Are all the rest of the html files renamed to php so they can include this? Or do all files stay html files, since isn't needed to bracket the include statement? Or does the include need to be within php code brackets? – curls Sep 07 '15 at 00:07
  • 1
    You need to put it between the PHP open and end tag like ``. You also have to rename every file you put that line into from .html to .php, otherwise the PHP parser won't do it's work. – PeterPan Sep 07 '15 at 00:09
  • That worked! Other than renaming and uploading everything again.... this is amazingly easy and clean. Whew. – curls Sep 07 '15 at 00:30
  • 1
    I'm glad that worked! – PeterPan Sep 07 '15 at 11:23