CSS Grid, 2-column interface design, dual vertical scrollbars and handling 100% height disparities

Hey there! I'm in the process of designing a dashboard UI using CSS grid. Do you think CSS Grid is the right choice for this project? I'd love to hear your thoughts.

Currently, I'm facing a challenge with implementing a sidebar that needs to be 100% height with an overflow scrollbar when the content exceeds that height. The sidebar should have a default minimum width of 100px, but expand when toggled without resorting to arbitrary values.

The ultimate goal is to achieve a responsive 2-column layout with two scrollbars, a full-height sidebar column, and a main column featuring a header navbar.

If you need visual references, here's what I'm aiming to build: View Image

Here's what I've done so far: CodePen Link

function toggleClass() {
  console.log("test");
  document.querySelector('.app-sidenav').classList.toggle("expanded");
}
*,
*:before,
*:after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: sans-serif;
}

/* mobile first */
.app-layout {
  display: grid;
  height: 100vh;
  grid-template-rows: auto 1fr;
}

... (CSS code continued)
(HTML structure included)

I would really appreciate any suggestions or advice on how to tackle this challenge. Thank you!

Answer №1

Check out this demonstration in a jsfiddle: https://jsfiddle.net/79ujhxdz/1/

I made minimal changes to your original code. To create the sliding side navigation, set its position as fixed, height as 100vh, and transition it in and out of view:

.app-sidenav {
  position: fixed;
  grid-column: 1;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-width: 100px;
  background: grey;
  width: 250px;
  height: 100vh;
  transform: translate(-250px);
}

.app-sidenav.expanded {
   transform: translate(0);
}

When the side navigation is expanded, adjust the main content to move to the right and reduce its width by the sidenav's width to prevent horizontal scrolling:

.app-main.sidenav-expanded {
  transform: translate(250px);
  width: calc(100% - 250px);
}

In the HTML structure, I relocated the header within the main content so that only .app-sidenav and .app-main are direct children of .app-layout.

The JS portion now toggles classes for both .app-sidenav and .app-main. Alternatively, you could toggle a class on the parent .app-layout and let inheritance handle the styling for these two elements in your CSS.

function toggleClass() {
  document.querySelector('.app-sidenav').classList.toggle("expanded");
  document.querySelector('.app-main').classList.toggle("sidenav-expanded");
}

Lastly, I eliminated the @media queries from the CSS that handled desktop responsiveness to keep the jsfiddle CSS clean and more comprehensible.

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

Ways to prevent images from vanishing when the mouse is swiftly glided over them

Within the code snippet, the icons are represented as images that tend to disappear when the mouse is swiftly moved over them. This issue arises due to the inclusion of a transition property that reduces the brightness of the image on hover. However, when ...

Ways to eliminate hover effect in CSS

I have a text that is currently displayed as a hyperlink, and some CSS code is causing it to underline and become bold when hovered over. I want to remove the hyperlink, but still keep this style by default without needing to hover over the text. Here is m ...

A step-by-step guide on incorporating click and drag events into an HTML Canvas

I have developed a unique business tool using html canvas. It is equipped with a variety of draggable and droppable elements. I personally created the functionality with the following pseudocode: if(mouseIsDown && mouseInBoundsOfIcon){ icon.g ...

What could be the reason for Sass failing to return the updated value of a global variable that was modified within a function?

While experimenting with sass @function, I made an interesting discovery. When my variable is declared as global scope, the function fails to apply changes to this variable and only returns its initial value. However, when I declare the variable as functio ...

Sending a Form using jQuery and Ajax

Struggling with getting my register page to post the data to the database using Ajax and jQuery. I'm new to ajax and can't quite figure out how to do this insert. Any advice on how to achieve this would be much appreciated. I'm not even sure ...

Row-eq-height does not function properly with the layout of my webpage when trying to bootstrap equal column heights

I am currently building a webpage and struggling with keeping the left orange div at the same height as the right div. The navigation is represented by the orange div, which contains links. Upon clicking a link, a preview of a .pdf file appears in the righ ...

Show all information from MySQL tables in an HTML format

I need help with displaying an entire mysql table within an HTML table. I've come across some code that is able to show the fields: <?php $con=mysqli_connect("example.com","peter","abc123","my_db"); // Check connection if(mysqli_connect_e ...

Retrieve Images from URL - Similar to Facebook Thumbnails

I am in the process of creating a website similar to "Reddit." Users will have the option to share URLs, and I would like to use PHP to extract the correct image from these links. What I'm looking for is a more advanced script that can retrieve imag ...

Sorting table by priority in HTML is not functioning as expected

I am currently developing this code for a SharePoint 2010 platform. While the table can currently be sorted alphabetically, I am looking to implement a different functionality. Unfortunately, I am facing an issue with changing variables 'a' and ...

When receiving a GET response after a server crash

Question: I am sending a Get request through Ajax every second and waiting for a response from the server. However, if my application crashes and I keep sending requests every second, I only receive a server timeout error (HTTP status code 502) with no oth ...

Setting the row property of a frameset using CSS: a step-by-step guide

What is the best way to set the frameset row property using css or jquery for various browsers? ...

Clicking will close any other sub-menus

Greetings everyone, Thank you for taking the time to read through this post. I am currently facing an issue while attempting to create a menu with sub-menus. Here are the requirements for the menu: Sub-menus should open on click. (working) Selected sub ...

Rearrange the <div> elements by dragging and dropping them after they have been appended

I have a pair of buttons available: <a href="#" class="add">+ Add 1</a> <a href="#" class="add2">+ Add 2</a> Upon clicking these buttons, I am able to generate multiple divs as needed. This functionality has been achieved using th ...

Issue with Hover Effect on Safari Browser

Encountering a peculiar issue exclusively in Safari - when hovering over a link in the header, the links to the right of the hovered-over link alter their size (appearing smaller) during the hover animation. Once the animation concludes, these links revert ...

What is the method for viewing the content within div tags on an apex page?

Locationbox is a system outside of Salesforce, similar to Google Maps. An example can be viewed here; I am aiming to integrate it into the Salesforce platform. The first script tag fetches JavaScript code from the Locationbox service. Once the startup() f ...

The update query appears to be malfunctioning

I am currently working on implementing Add, Update, and Delete functionalities in PHP. Everything seems to be functioning well, except for my Update query which is causing issues. Can someone please assist me in identifying the error in my Update query? ...

The spacing within the table's <tr> elements does not get altered

I am struggling to add a small space in the table <tr> but my attempts have not been successful. How can I resolve this issue? Please refer to the image below for clarification: https://i.sstatic.net/HXdhq.png .panel-booking .panel-body { pad ...

Error encountered during npm installation caused by the extract-text-webpack-plugin

I encountered an error while attempting to install the extract-text-webpack-pluginpm plugin. extract-text-webpack-plugin <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f12124c5e495a125b5a495e4f4f7f0f110e110f">[email  ...

Convert HTML special characters to ASCII characters using JavaScript

Does Javascript have a specific function for this type of replacement? (replaceAll) PARAMS+= "&Ueberschrift=" + ueberschrift.replaceAll(">",">").replaceAll("<","<"); PARAMS+= "&TextBaustein=" + textBaustein.replaceAll(">",">"). ...

Issue with jQuery .hover() not functioning as expected

The issue I'm encountering is just as described in the title. The code functions correctly on all divs except for one! $(".complete-wrapper-1").hide(); var panelHH = $(".file-select-wrapper").innerHeight; $(".files-button").hover(function(){ $(" ...