For this you need to use JavaScript and jQuery.
There are several ways to do this.
Option 1
Create index.html, specify <div class="container">
and leave this field blank. Then use jQuery to load home.html
into the .container
object and do the same for all other pages.
$(document).ready(function() { $(".container").load("home.html"); }); $("ul.navbar-nav li").each(function() { $(this).on("click", function{ $(".container").load($(this).attr("data-page")+".html"); }); });
In this case, the href
value of your URL should always be "#", and you must give it data-page="about"
if you want it to display the about page.
Option 2
Create all divs on one page, give them a class that hides them, use jQuery to hide all divs, BUT the one you want to show.
<div class="container"> <div id="home"></div> <div id="about" class="hidden"></div> <div id="contact" class="hidden"></div> </div>
Your JavaScript file:
$("ul.navbar-nav li").each(function() { $(this).on("click", function{
You can read on this page to find out how Bootstrap does this, so you don't have to write it yourself.
source share