Guide on setting up sidebar navigation

I am looking to enhance my html page with a sidebar navigation menu. Here is the current code snippet:

    <html>
    <head>
    <title>Admin dashboard</title>
    </head>
      <header style="height:100px; background-color:#666; padding-   top:35px"><h2 style="color:#FFF">Dashboard</h2></header>
     <body>
     <div style="width:100%; height:100px">

       <div style="background-color:#aaa; height:550px;width:200px;float:left;">
       <div><b>Main Menu</b></div>
       HTML<br />
       PHP<br />
       PERL...
       </div>
       <div style="background-color:#eee; height:550px;width:1132px;float:left;">
      <p></p>
      </div>



      <div style="background-color:#b5dcb3;clear:both">
    <center>
     Copyright@GIMT
    </center>
    </div>
    </div>
    </body>
    </html>

I would like to incorporate a sidebar navigation menu into the existing code. This is the part where I want to make the addition:

<div style="background-color:#aaa;  height:550px;width:200px;float:left;">
             <div><b>Main Menu</b></div>
              HTML<br />
                PHP<br />
               PERL...
              </div>

Can anyone guide me on how to achieve this?

Answer №1

Before we dive in, here are a few important notes:

  1. Always include <!DOCTYPE html>.
  2. Your content should always be within the <body> tags. The <header> tag should come after.
  3. Avoid using inline styles.
  4. Utilize CSS positioning for fixed elements and other styling purposes.

Code Snippet

* {
  margin: 0;
  padding: 0;
  list-style: none;
}

header {
  background-color: #666;
  color: #fff;
  line-height: 2.5;
  padding: 10px;
  height: 80px;
}

main {
  padding-left: 220px;
}

aside {
  position: fixed;
  left: 0;
  width: 200px;
  background-color: #aaa;
  top: 100px;
  bottom: 0;
  overflow: auto;
}
<header>
  <h1>Dashboard</h1>
</header>
<main>
  <aside>
    <h3>Main Menu</h3>
    <ul>
      <li>HTML</li>
      <li>PERL</li>
      <li>PHP</li>
    </ul>
  </aside>
</main>

Note: I've included overflow: auto for the sidebar to ensure that if content exceeds the area, scrollbars will appear without affecting the main content's scrollbars.

Code Snippet with Extended Content

$(function () {
  $("aside ul").append(function () {
    return Array.apply(null, {length: 101}).map(Number.call, Number).map((x) => "<li>Item " + x + "</li>").join("");
  });
});
* {
  margin: 0;
  padding: 0;
  list-style: none;
}

header {
  background-color: #666;
  color: #fff;
  line-height: 2.5;
  padding: 10px;
  height: 80px;
}

main {
  padding-left: 220px;
}

aside {
  position: fixed;
  left: 0;
  width: 200px;
  background-color: #aaa;
  top: 100px;
  bottom: 0;
  overflow: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
  <h1>Dashboard</h1>
</header>
<main>
  <aside>
    <h3>Main Menu</h3>
    <ul>
      <li>HTML</li>
      <li>PERL</li>
      <li>PHP</li>
    </ul>
  </aside>
</main>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Implementing a feature to apply the 'current' class to a div

How can I dynamically add a current class to the .navimg divs (next to li) when their parent link is clicked? Sample HTML: <div id="navbox"> <ul id="navigation"> <li id="home"><a href="#">HOME</a></li> ...

Material UI does not support the inline attribute for applying CSS properties

Trying to adjust the CSS for Material-UI When setting the width, everything works fine. However, when attempting to set display inline, an error occurs ---> "inline is not defined" Can anyone provide guidance on how to resolve this issue? Sharing my cod ...

Developing a desktop app using HTML5

I'm starting out with HTML (specifically HTML5) and I'm interested in developing a desktop widget using HTML5 without having to rely on running it within a browser. Are there any software development environments available that can assist with th ...

Creating a new webpage that automatically populates with multiple images from a server using PHP

I'm inquiring about generating a webpage automatically from an HTML template, How can I create a new webpage from an HTML template and display multiple images from the server on the generated page? Please review my code below, Thank You. The follo ...

When the width of the element is set to 100vw, it disrupts the

I'm attempting to expand a sticky element to fit the size of the screen. Here is the HTML code I am using: .large { height: 200vw; width: 200vw; } .header { left: 0; top: 0; color:white; position: sticky; width: 100px; height: 10 ...

Should you create an archive - Retain outcomes or retrieve them whenever needed?

I am currently developing a project that allows users to input SQL queries with parameters. These queries will be executed at specified intervals determined by the user (e.g., every 2 hours for 6 months), and the results will be sent to their email address ...

Guide to creating the onclick feature for a dynamic button in Meteor

<template name="actionTemplate"> {{#each action}} <button class="myButton" id={{_id}}>btn</button> {{> action}} {{/each}} </template> <template name="action"> <div class="sct" id={{_id}}> ...

Tips for merging identical media queries into a single query using SASS

Previously, I organized my media queries in LESS by combining them at a single place like this LESS: .media-mixin(@break) when (@break = 1200px) { .abc{ color: red; } } .media-mixin(@break) when (@break = 1200px) { .xyz{ color: yellow; ...

Responsive design with Bootstrap grids

In the current 3 column layout, as the browser window size decreases, the columns stack in the order of first, second, and third. However, I want the behavior to change so that when the columns get smaller, they stack in a different order. First - This ...

The alignment of the horizontal menu items is off

Currently, I am working with asp.net and dealing with a horizontal menu issue. The alignment problem arises where the right side of Menu B appears higher than the left one (Menu A). I have included my code below for reference. Any suggestions or assistance ...

Unleash the potential of a never-ending expansion for grid cells on Canvas

ts: templateStyle = { display: 'grid', 'grid-template-columns': 'calc(25%-10px) calc(25%-10px) calc(25%-10px) calc(25%-10px)', 'grid-template-rows': '150px auto auto', 'grid-gap ...

Live updates for downloads page menu using HTML and Bootstrap

I'm currently working on a menu page that features 3 tabs: Windows, Linux, Mac. When you click on the Windows tab, it will not only download the windows installer but also display installation instructions specific to Windows. Similarly, when you sele ...

Creating uniform height for dynamic MdBootstrap cards

I am attempting to ensure uniform height for these cards regardless of the length of the movie title. The cards are dynamically generated and I am using swiperjs for carousel functionality. Just to clarify, these are mdBootstrap cards. Below is the code sn ...

JavaScript code for validating two passwords is malfunctioning

I'm currently working on a registration form for my website and I'm trying to implement a JS script that compares two password inputs (password and repeat password) and displays a message saying "passwords are not the same." Below is the code I h ...

Could use some assistance in developing a custom jQuery code

Assistance Needed with jQuery Script Creation <div>Base List</div> <div id="baseSection"> <ul class="selectable"> <li id="a">1</li> <li id="b">2</li> <li id="c">3</li> ...

Creating PDF files with PDFkit in Node.js while rendering HTML data

I am looking for a way to generate a PDF file using the 'PDFkit' library. The data is being retrieved from a MySQL database, and some of the content includes HTML tags. However, when I try to render the HTML data to PDF using the 'html-to-te ...

Minimum and Maximum Price Input Field

Hello everyone, I'm currently facing an issue with a code that is supposed to filter with minimum and maximum price values, but it's not working as expected. Below is the HTML form snippet: <form> <select class="custom-select my ...

Toggle Class Based on Scroll Movement

I am currently designing an HTML page that includes a small navigation bar located halfway down the page. I am aiming to have this navigation bar stick to the top of the page (become fixed) once it reaches the top. Here is the code I have tried: The scrip ...

Toggling the visibility of a div using JavaScript

When I click the button, I want to show and then hide a div. However, it doesn't work on the first click - only on the second click. How can I make it work on the first click? HTML <p>Click the button</p> <button onclick="myFu ...

unable to adjust the maximum height limit

I've been struggling to set a maximum height on the slider I'm currently using. No matter what height value I input, it doesn't seem to take effect. Additionally, I attempted setting the width for the echo img row in the PHP section but enco ...