Ways to implement a CSS transition effect on a sidebar menu?

I successfully implemented a sidebar menu and now I am looking to enhance its appearance by adding transitions for a more polished look. Below is a snippet of my current code:

$('.menu-toggle').on('click', function() {
  $('body').toggleClass('nav-md nav-sm');
});
.sidebar {
  position: absolute;
  top: 35px;
  right: 0px;
  bottom: 0px;
  left: 0px;
  width: 180px;
  background-color: #0071bc;
  color: #fff;
  height: 100%;
  overflow: auto;
  font-size: 9pt !important;
  white-space: nowrap;
}

.sidebar a {
  color: #fff;
}

// Additional CSS rules here

#main-container-fluid {
  padding: 0 5px;
}

ul li {
  list-style: none;
}

ul li:after {
  content: "\A";
  white-space: pre;
}
<html lang="en">

<head>
// HTML head content here
</head>

<body class="nav-md">
 // Body content here
</body>

</html>

I am seeking a solution to make the sidebar menu transition in slowly when the user clicks on the bars icon. Any examples or suggestions would be greatly appreciated. Thank you.

Answer â„–1

To create a hidden and visible sidebar, you can utilize the transition and transform properties in CSS. Below is a simple implementation:

.container.body #main-content-area,
.container.body .sidebar {
  /* these two elements will transition over 300ms when transformed */
  transition: transform .3s;
}

.nav-md .container.body #main-content-area {
  transform: translate(180px);
}

.nav-sm .container.body .sidebar {
  /* the sidebar will be hidden by being 180 pixels offscreen */
  transform: translate(-180px);
}

The new CSS code replaces the following:

.nav-md .container.body #main-content-area {
  margin-left: 180px;
}

.nav-sm .container.body #main-content-area {
  margin-left: 0px;
}

.nav-sm .container.body .sidebar {
  display: none;
}

Here's a functioning demo:

$('.menu-toggle').on('click', function() {
  $('body').toggleClass('nav-md nav-sm');
});
.sidebar {
  position: absolute;
  top: 35px;
  right: 0px;
  bottom: 0px;
  left: 0px;
  width: 180px;
  background-color: #0071bc;
  color: #fff;
  height: 100%;
  overflow: auto;
  font-size: 9pt !important;
  white-space: nowrap;
}

.sidebar a {
  color: #fff;
}

header.pg-header {
  position: fixed;
  left: 0px;
  top: 0px;
  width: 100%;
  z-index: 3;
  border-bottom: 2px solid #0071bc;
}

header.pg-header .navbar>a.menu-toggle {
  color: #0071bc;
  cursor: pointer;
}

... (Additional CSS code omitted for brevity)

</html>

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

CSS menu that is activated on click

I'm currently working on creating a responsive menu, but unfortunately, I'm facing issues with getting the menu to open. Any assistance or advice would be greatly appreciated. <navi> <div class="gizli"><i class="fa fa ...

Implementing a dual-column design for MailChimp using HTML and CSS

I'm feeling overwhelmed. I have a MailChimp layout that I exported from MailChimp. Currently, the layout consists of 3 columns, but on mobile, it converts to 1 column. Here is the link to the codepen: goo.gl/Fj8Ct7 Is there anyone who can assist me ...

Enhance the appearance of 6 image URLs by wrapping them in dynamic divs with the

Can someone assist me in displaying 6 images retrieved from a MySQL database on an MVC Razor view? Images 1 and 6 should be placed in separate divs labeled "item", while images 2, 3, 4, and 5 should be grouped together in a div called "item-small". Below i ...

How can I use jQuery to create an onClick event that expands text content on the right side of a portfolio

Hi there, I'm attempting to achieve a similar effect as the hover action in my first fiddle. I'd like to use jQuery click/toggle to expand the content instead of displaying it on hover. I've been working with basic addClass using jQuery/CSS ...

How can I navigate and click on a drop-down menu link in Python using Selenium and CSS selectors?

This is an example of the HTML code: <span class="MenuIcons searchButton"></span> ... (additional content) <a data-bind="" url="/ParagonLS/Search/Property.mvc/Index/1" tabdescription="RESIDENTIAL" subtabdescription="Criteria" subtab ...

Icon toggling menu bug

I recently designed a menu featuring an animated icon that, when clicked, opens with two columns. The issue I'm facing is that after clicking on a link in the right column (view JSFiddle), the menu disappears but requires two additional clicks on the ...

What steps should be followed to construct a window identical to the one depicted in the attached image using HTML and CSS?

Check out this link to see the window style I'm trying to recreate using HTML, CSS, and Javascript. No Jquery needed. Thank you in advance. ...

Tips for ensuring a cloned table header remains fixed when scrolling through a page

Check out my code snippet on Pastebin: http://pastebin.com/pUstKXJz I'm trying to make a sticky header that stays at the top of the page when I scroll past 100 pixels. The current JQuery code I have isn't working properly, so I need help modifyi ...

Issues with loading SASS or source maps arise when dealing with nested structures

After reorganizing my SASS files into a nested structure, I encountered an issue where inspecting elements in Chrome led me to incorrect source maps. For instance, when trying to inspect a button, instead of being directed to the _buttons partial as expect ...

What is the best way to connect an HTML image to effortlessly switch between displaying and hiding an element (specifically, a table) using JavaScript?

Apologies if my question is a bit confusing and poorly written, as I am new to coding and Stack Overflow. What I am trying to achieve is the ability to click on each image and have a different table pop up for each planet with facts (an example of the Merc ...

Looking to make changes to the updateActivePagerLink setting in JQuery Cycle?

I'm in the process of developing a basic slideshow with 3 images, and I am relatively new to Jquery and Cycle. The slideshow is functioning properly, and the 3 pager links are also functional. The only remaining task for me is to implement "activeSli ...

Utilize the hexadecimal color code as a string within the darken function

When working with a less style, I have a string variable. @colorString: 'DADADA'; I can convert it into a color: @color: ~'#@{colorString}'; Then, I am able to use @color to define a value in a style: div { color: @color } However ...

The issue persists with the customized Bootstrap carousel featuring thumbnails

By combining http://codepen.io/srkimir/pen/mGbrf and http://codepen.io/transportedman/pen/NPWRGq , I successfully created a fading carousel with thumbnails similar to the one in http://codepen.io/kikibres/pen/gpZoXz . However, when trying to implement ...

What is the reason behind genNewColor function's malfunction?

I'm having trouble with this code that is supposed to generate a random color. The CSS formatting works perfectly, but I suspect there might be an issue with the function itself. When I try to run the code, it doesn't produce any error messages â ...

Incorporating tags into the react-select component

https://i.sstatic.net/Fsknq.pngI am still a beginner in the world of react-js. Currently, I am experimenting with the following: https://i.sstatic.net/4Ggoz.png This is what I have attempted so far: const options = [ { value: 'chocolate', ...

Obtaining rotate3d values using JavaScript / jQuery

When dealing with an element that has a transformation like the following: style="transform: rotate3d(1, 0, 0, -50deg);" I am looking to extract the value -50 using Javascript or jQuery. It's essential for me to get the absolute value, so negative d ...

What steps should I take to modify my navigation menu to display 'Logout' once a user is logged in?

I'm currently working on a small project to create a basic website and I am struggling with implementing a feature in PHP that changes the menu navbar to "Logout" once the user has successfully signed in. Below, you can find the navbar code as well a ...

Issue with Google Maps functionality within the jQuery easytabs platform

Upon clicking the contact tab, the gmaps loads but unfortunately only shows the left corner of the map. Quite intriguing... Any thoughts on how to fix this? Here is the corresponding jsfiddle This is the structure of my HTML code: <div id="menu-contai ...

Exploring ways to create a dynamic background image that allows the rest of the page to float over seamlessly

Currently working on a responsive website and almost done with the build. However, I came across a site where an image appears to be floating behind the rest of the webpage content. Tried searching for a solution using w3.css without any luck. Any sugge ...

Tips for adjusting text sizes at different breakpoints in Quasar

I encountered an issue while attempting to customize font size and line height for each variable in quasar.variables.scss. Here is the error message that was displayed: [plugin:vite:css] Undefined operation ""(600px,) > 0". ╷ 6831 │ ...