Is there a way to include an external HTML page (a nav menu) into every page. I had to redo a nav bar for a website and it’s all HTML/CSS and I really don’t want to copy and paste it into all 25 pages.
Can you use HTML and CSS with a PHP include function? Does it matter if the CSS is in a different external file with the rest of the CSS?
As you probably guessed, you would need PHP for this. Including an HTML file ( or any text data, for that matter) is no different than including a php file: include ‘path/toMy/file.html’; For best results, the included files should only the the exact text you want to include ( in other words, DONT create a proper page with header, htm, body… etc… just the markup for the nav. you will also need to change your FINAL pages so that they are .php documents and not HTML (or else the server wont know that the <? include file.php?> is a php and not a html command.
Does it matter if the CSS is in a different external file with the rest of the CSS?
not exactly certain what you mean here …
If you are just using PHP to import the CSS to a style tag… you should just use a link:
PHP has nothing to do with CSS really. PHP gets processed on the server, so what arrives at your browser is just HTML and CSS. So if your page pulls in some HTML with classes or IDs, they get styles just like normal, as they are just a normal part of the page that gets shown to the browser.
Just put the styles for you menu in your normal CSS file.
You can actually use PHP includes on your pages even if they are .html files, though it’s not ideal. I put up a little tutorial on using includes here.
Thanks for the help. Everything was already saved as PHP files which made that a lot easier.
I was asking if the CSS for the nav had to be inline with that include page or if it could be with the rest of my CSS, but it doesn’t matter where it is as long as it’s linked on the page.
Yes, avoid inline styles. As far as the browser is concerned, there’s no such thing a an include file. It just sees all the content on the page with no idea where it came from, and applies the styles in the style sheet to what it sees in the HTML.