treehouse : what would you like to learn today?
Web Design Web Development iOS Development

css menu repeat on HTML ?

  • Hello

    I'm read manual about CSS. There are some CSS menu examples.
    But i have question about HTML. This is test html page (like main page)


    <HTML>
    <HEAD>
    <LINK REL="stylesheet" TYPE="text/css" HREF="nav.css"/>
    </HEAD>
    <BODY>
    <DIV id="navigation">
    <UL>
    <LI><A HREF="firstpage.html"> link1 </A></LI>
    <LI><A HREF="secondpage.html"> link2 </A></LI>
    <LI><A HREF="thirdpage.html"> link3 </A></LI>
    </UL>
    </DIV>
    </BODY>
    </HTML>


    So if i want keep menu on firstpage.html, secondpage.html, thirdpage.html pages i need repeat this code there ? I must do it on all HTML pages ?



    Thanks
  • You can use php so you only have to change it once.
  • Create a file like 'navigation.php' - then instead of the HTML on each page you can put:
    <?php include('navigation.php'); ?>
  • How about Ajax?
  • What does Ajax have to do with this?
  • Didn't you know Doc? Ajax is amazing, it's the solution for all your web problems!

    Solve everything with Ajax!
  • Dont know about Ajax but usually I use php include, I thinks the best way to insert a menu.
  • You can also use an iframe, just be sure to put target="_parent" on all links inside the iframe.
  • I can't tell if that iframe comment is a joke or not. So just to make sure the OP doesn't get confused, do not use an iframe for this.
  • Why not use an iframe for this? I've been doing it for a while.
  • Browser compatibility for one. It seems so simple but there are some definite quirks for some browsers. I've read a few instances of IE9 going a little bonkers.

    In this case, the OP isn't trying to create some application where an iframe would (naughtily) be required. Using a PHP include would make it be a 'single page', not two pages that the browser has to render independently.
  • I've tested it all the way back to IE5, it seems to work fine for me.
  • It's funny, I don't really have an argument outside of simply knowing that it's wrong.
  • Haha I was going to add I was taught never to do it, but then I couldn't recall what any reasons were... hmm...
  • I must say, I'm the type of person that breaks tradition if this no reason behind it. :) Here's a site that I did with iframe nav, everything seems to work fine.
  • @cnwtx, php would be better from the vantage point of site performance. An iframe requires that the page requests the external iframe (nav, template part, etc.) be loaded as an additional resource to the page, at the browser level. A php include is processed on the server and the file is served as a singular entity to the client, no additional request needed by the browser. Does that make sense?