如何制作更改主要内容时不必重新加载的侧边栏?



我有一个固定的侧边栏,它正在工作,我喜欢它,但我不希望每次我想更改主要内容时都必须重新加载它。我也不想在我想做更改的时候,一遍又一遍地把它复制粘贴到每个内容页面上。我的想法是,有没有一种方法可以将侧栏和内容分开,但同时显示它们?

如果您希望它们保持在同一页面上,我建议您尝试单页方法或SPA,如果您使用#来针对特定的id,例如:

<body>
<header>
<ul class = "nav" style = "display:flex;list-style:none;position:fixed;top:0;left:0;">
<li class = "navlink"> <a href="#homepage"> Home </a> <li>
<li class = "navlink"> <a href="#products"> Products </a> <li>
<li class = "navlink"> <a href="#orderstatus"> Order status </a> <li>
<li class = "navlink"> <a href="#support"> Customer Support </a> <li>
</ul>
</header>
<section id="homepage">
<h1>homepage</h1>
<h1>homepage</h1>
<h1>homepage</h1>
<h1>homepage</h1>
<h1>homepage</h1>
<h1>homepage</h1>
<h1>homepage</h1>
<h1>homepage</h1>
<h1>homepage</h1>
<h1>homepage</h1>
<h1>homepage</h1>
<h1>homepage</h1>
</section>

<section id="products">
<h1>products</h1>
<h1>products</h1>
<h1>products</h1>
<h1>products</h1>
<h1>products</h1>
<h1>products</h1>
<h1>products</h1>
<h1>products</h1>
<h1>products</h1>
<h1>products</h1>
<h1>products</h1>
<h1>products</h1>
<h1>products</h1>
<h1>products</h1>
</section>

<section id="orderstatus">
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
<h1>orderstatus</h1>
</section>

<section id="support">
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
<h1>support</h1>
</section>
</body>

最新更新