Struggling to locate a straightforward sidebar solution without relying on Bootstrap. Finding an easy-to-use answer seems

I have a lightweight and easy-to-understand code for a website project with two panels.

The first panel on the left is a large navigation (270px width, top to bottom, similar to a wiki) with approximately 30 unordered list items. Next to it is the second panel which contains the content. I want it to be simple - just two elements, left & right, with no extra features like a navbar at the top or footer.

Here's what I need:

  • The first panel should have its own scroll bar independent from the second panel.
  • On a computer display, the first panel should appear and stay open by default.
  • On a mobile display, the first panel should appear closed initially.
  • A toggle button should allow users to open the first panel when needed.
  • Whether the content pushes aside or overlays doesn't matter.

I'm looking for a solution similar to the Simple Sidebar demo (linked here), but without all the excess code, dropdowns, vendors, and unnecessary Bootstrap components that are tedious to remove.

Is there a straightforward way to achieve this using HTML, CSS, jQuery, or even better, just a few lines of JavaScript? I want to avoid dealing with bloated Bootstrap code and frustrating menu configurations that seem to dominate search results...

Thank you to anyone who can provide a clear and simple resolution to this issue and help me escape this madness!

Answer №1

Check out this demo: See Demo

No Bootstrap, No jQuery, No vendor dependencies. This solution utilizes only CSS and JavaScript.

  1. The 1st panel will become scrollable when it contains enough elements.
  2. The 1st panel remains visible in desktop view.
  3. The 1st panel is initially hidden in the default mobile view. A toggle button will appear to reveal it.
  4. Clicking on the toggle button will display the 1st panel.

index.html:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1" name="viewport" />
    <title>CodePen - A Pen by Motahar</title>
    <link rel="stylesheet" href="./style.css">

</head>

<body>
    <div class="content-container">
        <div id="left-panel" class="left-nav-wrapper">
            <ul class="navigation-panel">
                <li class="nav-1 nav-tab active" onclick="openPage(event, 'contentName1')">Tab-1</li>
                <li class="nav-2  nav-tab" onclick="openPage(event, 'contentName2')">Tab-2</li>
                <li class="nav-3 nav-tab" onclick="openPage(event, 'contentName3')">Tab-3</li>
                <li class="nav-4 nav-tab" onclick="openPage(event, 'contentName4')">Tab-4</li>
            </ul>
            <div class="cross-btn" onclick="showNav()">
                <span>X</span>
            </div>
        </div>
        ... (Content of right pane)
    </div>
    <script src="./script.js"></script>

</body>

</html>

style.css

(CSS styles)

script.js

// Right Pane Active/Hide Content
function openPage(evt, pageName) {
    (JavaScript function code for handling content visibility)
}

// Left Pane Active/Hide Nav on Mobile
function showNav() {
    (JavaScript function code for toggling left panel visibility)
}

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

Incorporate a Background Image, which is linked to a website URL, by utilizing an external CSS file within

I am struggling to incorporate an external CSS file (specifically a background image from a URL) into my HTML document. I have successfully applied internal CSS, so the issue is not with the website link. Despite reviewing similar posts addressing comparab ...

Is it possible to simultaneously verify if an array is empty within an Object along with checking the other fields?

Let's say I have an object that has the following structure: filter: { masterName: '', service:[], } What is the best way to determine if both the array and masterName field are empty? ...

AngularJS $http get isn't functioning properly, but surprisingly $.ajax works perfectly

Recently delving into the world of AngularJS, I am facing a hurdle with $http functionality. In my factory setup below: app.factory('employeeFactory', function ($http) { var factory = {}; // Retrieving data from controller var emplo ...

Setting up a connection to MongoDB on a local network using express and mongoose

As I set up a server with express and mongoose, my goal is to make it accessible on other devices within my local network. To achieve this, I configured the bind_ip variable to 0.0.0.0 in the Mongodb configuration file. const connection = mongoose .co ...

Error 404 encountered while attempting to download a file through the <iframe> and AJAX method

I am currently utilizing an iframe to initiate the downloading process of an excel file from the server via an AJAX request. Each time a button is clicked, the server generates an excel file within approximately thirty seconds and sends back the correspond ...

The post request is successful in Postman and cURL, however, it faces issues when executed in Angular

A remote server and a local client are set up to communicate through a simple post request. The client sends the request with one header Content-Type: application/json and includes the body '{"text": "hello"}'. Below is the s ...

Achieving 10 touchdowns within a set of 5 plays during a football game

Receiving a page from an external site where I have no control. The table structure is as follows: <table><tbody> <!-- headers --> <tr><td></td> <td></td> <td></td> <td>< ...

Most efficient method for dynamically changing HTML content with JavaScript

Can anyone provide guidance on how to switch HTML content using JavaScript? For example: if($sid == 0) {insert one HTML code} else {insert another HTML code} Which method is preferable - LESS, jQuery, CSS3, etc? ...

What are the implications of declaring a controller as a variable within itself or utilizing $scope?

As I dive into learning and utilizing AngularJS, certain concepts still remain unclear to me. Here is my query: within my application, there is a controller that utilizes $http to fetch data from the backend upon initialization. Following a comprehensive ...

Issue with Bootstrap JQUERY Plugin in External Modal

product.php <a data-toggle="modal" data-target="#quick_edit" href="quick_edit.php?productid=<?php print $row['productid'];?>" class="btn btn-xs btn-success"><i class="fa fa-share"></i></a> <div class="modal" id= ...

JavaScript: Struggles with utilizing a function as an argument and later executing it inside a nested function

I've been struggling with defining a new function, and I need help resolving it. Here's an example that I was initially referencing: Pass arguments into ajax onreadystatechange callback? I wasn't able to find the solution through research, ...

What is causing the duplication of Google Map drawing controls?

I've been trying to integrate the Google Maps JavaScript API into my React project to create a map with polygon drawing capabilities. The map itself is functioning perfectly fine, but I'm encountering an issue where two sets of drawing controls a ...

Navigating across various iFrames with the help of XPath and C#

Trying to extract a data element from a table that is nested within two iframes. These frames are displayed like this: <iframe id="appContent" frameborder="0" name="appContentFrame" src="/controller.aspx" style="height: 0px; width: 1319px;"> ...

Which framework should be used: client-side or server-side?

I am working on a project similar to craiglist, where users can post announcements for everyday items like cars and flats. I have already developed a significant portion of the backend using a RESTful API in three-tier architecture with Java, connecting to ...

The Material UI appbar fails to resize properly on mobile devices

I have added a material-ui appbar to the top of my website. Check it out here: Website Appbar However, when I resize the website to mobile size, the appbar does not adjust responsively to the screen. Here's how it looks on mobile: Appbar when in mobi ...

Homepage experiencing issues with Jquery slider functionality

I have been attempting to incorporate a slider on my magentogo store, but unfortunately, after following all the code from the demo example of the slider along with the necessary CSS, the slider refuses to work. The CSS is configured to display none, as th ...

What are the consequences of submitting a form to a different website through POST method?

Dealing with a CMS that does not offer an easy way to add a NodeJS route for handling form data can be quite challenging. I'm considering the following setup - would this be considered bad practice or unsafe? Server 1 (Ghost CMS) : www.domain.com &l ...

Using Buttons to Filter Data in React

My goal is to implement button functionality that filters data from a JSON file. Upon clicking a button, the state should be updated with the filtered JSON data and display the list with the updated information. Currently, I have four buttons for filteri ...

Performing an AJAX request using jQuery without specifying the method name in the URL

Is the Page_Load method called if only the page name is specified in the AJAX call URL? $.ajax({ type: "POST", url: "PageName.aspx", //No method name data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: fu ...

Firefox is unable to display SWF files

My code snippet: <div id="sw" style="cursor:pointer" > <object id="swfobj" type="application/x-shockwave-flash"> </object> The JavaScript part: function openfile(filePath) { $("#swfobj").attr("data", filePath); $("#sw ...