When using jQuery and CSS to dynamically change properties, the element may receive scroll

<!DOCTYPE html>
<html>
<head>
        <title>CUSTOM PAGE</title>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1" name="viewport" />
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
    <script
  src="https://code.jquery.com/jquery-3.3.1.slim.js"
  integrity="sha256-fNXJFIlca05BIO2Y5zh1xrShK3ME+/lYZ0j+ChxX2DA="
  crossorigin="anonymous"></script>
  <style type="text/css">
    body{
        margin: 0;
        padding: 0;
    }
    #side{
      width: 20%;
      height: 100%;
      left: -20%;
      position: fixed;
      background-color: darkgreen;
      transition: 0.7s;
    }
    #main{
      width: 100vw;
      max-width: 100%;
      max-height: 100%;
      height: 100vh;
      background-color: red;
      transition: 0.7s;
    }
    #menu{
      width: 100%;
      height: 10%;
      background-color: grey;
    }
  </style>
</head>
<body>
    <div id="side"><button id="close">close</button></div>
  <div id="main"><div id="menu"><button id="open">Click Here</button></div></div>
  <script type="text/javascript">
    $("#open").on("click", function(){
      $("#side").css("left", "+=0%");
      $("#main").css("margin-left","+=20%");
    });
    $("#close").on("click", function(){
      $("#side").css("left", "-=20%");
      $("#main").css("margin-left","+=0%");
    });
  </script>
</body>
</html>

I am creating a unique page layout with a sidebar and main content area. The main part should act like the body of the page without any issues. However, I encountered a problem when opening the sidebar which slides in from the left. This action causes the page to receive a vertical scrollbar which is unwanted. Despite trying various solutions, the issue persists. View the image showing the vertical scrollbar here.

Answer №1

Please remove the width: 100vw; from the #main ID

#main{
 /* width: 100vw; This line should be deleted */
    max-width: 100%;
    max-height: 100%;
    height: 100vh;
    background-color: red;
    transition: 0.7s;
}

Take a look at it Here, and let me know if that solves the issue!

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

What is the process for rendering content with renderajax?

I'm having trouble trying to render the view create.php using renderAjax in the controller. I've tried different methods but can't seem to make it work properly. The problem is that the js files (select2, datatables, etc) are not loading. I ...

What happens when browsers encounter unfamiliar attributes in HTML code

Direct and to the point: if I were to execute: <div id = "thisid" class = "a plethora of classes" mother = "your mother" levelofhotness = "over 9000"> I am aware that Chrome and Firefox (the browsers I typically test with) simply disregard these a ...

Challenges surrounding jQuery's .before

Currently, I am in the process of creating a simple carousel consisting of 4 divs. The carousel is utilizing 2 jQuery functions to position a div at either the first or last slot. The transitions being used are only alpha transitions as there is no need fo ...

Incorporate functionality into a button using jQuery

I am working on a table that displays data in different levels (Parent, Child, Grandson). When I click on the parent row, it expands to show new rows related to the child level. Similarly, clicking on a child row reveals a third level known as the grandson ...

Saving an array of key-value pairs in local storage

I'm attempting to save an array in local storage using the following code: var tempval = []; tempval['key'] = 1; localStorage.setItem("Message", JSON.stringify(tempval)); However, when I check local storage, it only sho ...

Issue: AngularJS Injector Module Error

Recently started learning angularjs and trying to set up an app. Here's a simple and direct way to do it: Angular controller: (function () { 'use strict'; angular .module('myQuotesApp') .controller(' ...

The text color of the tabs turns black when a tab is selected - I receive my results after clicking anywhere on the screen

I am currently using HTML, CSS, and Bootstrap to design some tabs. Here is the current result I am achieving: https://i.sstatic.net/qbUck.png When clicking anywhere on the screen, I see the original results based on my code. The outcome after clicking a ...

Trigger the jQuery event only during moments of inactivity

My form includes a search input box that automatically pulls remote data based on the user's entry. To activate the search, at least 3 characters are required. For instance, typing "smi" will bring up all staff members with last names starting with " ...

Changing the height of SimpleBar in a component without using global styles in Angular

Is there a way to customize the height of my scrollbar without affecting other components? I tried using simplebar-scrollbar :: before in global style but it impacted other areas as well. I'm looking for a solution that only applies to my component. ...

How can I center align text after floating ul li elements to the left?

When creating a navigation bar with li elements floated left, the text also floats left. How can I center the text in the navigation bar? I have tried using text-align:center;, but it doesn't center the text on the y-axis. Some suggest using padding t ...

Arranging element in a vertical column

Looking for Help with CSS Positioning Solution to align 3 divs (left/center/right) inside another div I am struggling to position text in a column order. I have tried using float, but it affects other elements on the page. Below is my code snippet: < ...

After making an AJAX call, the table data can be found in page 1 under the tbody

Can anyone help me with this issue? I've gone through all the guides related to this problem and followed them step by step, but still no success. After populating the table using an AJAX call, all the data appears on a single page only. I attempted ...

Is there a way to replicate a DIV and its contents in ASP.NET using C#?

I am looking to create a form that can duplicate or clone itself when the CPF/CNPJ (Brazilian personal identification) onchange. Below is the current code I have: <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" r ...

JS unable to insert new row in table

I checked the input value before submitting it in the form and confirmed that it is correct, returning as a string.enter image description here const saveList = () => { const inputListNameText = inputListName.value; fetch('/api/lists' ...

Efficiency boost: Implementing ajax to load content

Let's discuss the best methods for optimizing content loading with ajax. I will outline a few techniques and provide my insights on each one. Loading html directly - This method makes it easy to load content without much additional processing requir ...

CSS styling can be used to generate a line break above and below a drop-down menu

While working on my CSS drop down menu, I noticed that it was generating unwanted line breaks before and after the dropdown. Below is the HTML code: <body> <!--nav class="navi"--> <div class="navi" id="navi"> <ul> <li& ...

Maximizing efficiency in JavaScript by utilizing jQuery function chaining with deferred, the .done() function

I am working on retrieving data from multiple functions and want to chain them together so that the final function is only executed when all the data has been successfully loaded. My issue arises when trying to use the .done() method, as it calls the func ...

Brainstorm: Creative ways to showcase excess content within a div

I'm struggling to find a suitable title for this issue. Essentially, I have a box-shaped div that expands into a rectangle and reveals content when clicked. The problem arises when I animate the div's width during expansion. Instead of positioni ...

Using jQuery to dynamically assign default selection in HTML

Currently, I have a line of code that dynamically sets the default selection of a selection box in html using jQuery. var y=...a value from the DB; this.$(".status option[value=y]").attr("selected", "selected"); The issue is that it only works if I ...

The search bar on the screen does not span the entire width as expected using Bootstrap CSS styling

I have a search form with an input field and a button. When I place the form in a standalone HTML file, the input and button span across the width of the div. However, when I embed it into the specific div I am working on, it shrinks to the left. Here is t ...