SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    External HTML page?

    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?

  2. #2
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,791
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    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:
    Code:
    <link href="style.css" rel="stylesheet" type="text/css" media="all">
    hope that helps.

  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,112
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by MVerminski View Post
    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?
    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.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,112
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by MVerminski View Post
    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.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •