The container does not extend to full size within the overflow area, resulting in no padding being applied

I've been encountering a persistent issue with this particular CSS problem where the overflowing content does not display the expected padding. To illustrate, take a look at this image:

https://i.sstatic.net/056IH.png

The challenge lies in setting padding for the internal container that overflows, yet somehow this padding doesn't carry over to the hidden area. Once you scroll to the end of the container, you'll notice the absence of padding.

Upon further investigation, I've identified the root cause as the internal container failing to expand completely within the overflow zone. To help clarify, I've prepared a fiddle.

   function toggleCollapseMenu() {
      document.getElementById("mainMenu").classList.toggle("uncollapsed");
    }
...

Upon expanding the menu to full-screen using the collapse button, the lack of vertical padding becomes evident at the bottom of the overflowing document.

For more reference, feel free to check out this alternate fiddle: http://jsfiddle.net/vkrs38qt/9/

In attempting to address this issue, I've tested adding the following code snippet to the overflown content (menu-container):

  min-width: 100%;
  width: 100%;
  margin: auto;

Despite my usual approach in similar cases, this adjustment had no impact on the container in my current scenario. In essence, I'm seeking guidance on how to apply padding consistently across overflowing content—both vertically and horizontally—from start to finish :)

If my explanation seems unclear, let's hope the provided code snippets and images can convey the situation effectively.

Answer №1

.menu-container ul inherits the overflow value from .menu-container, which requires overriding.

.menu-container ul {
...
  overflow: auto;
...
}

However, this can cause your content to be covered up. Changing the z-Index solves the issue horizontally, but there are still oddities vertically.

   function toggleCollapseMenu() {
      document.getElementById("mainMenu").classList.toggle("uncollapsed");
    }
:root {
  --height: 150px;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

ul {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

a {
  text-decoration: none;
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#collapseBtn {
  display: inline-block;
  cursor: pointer;
  background-color: black;
  color: white;
  padding: 0.5rem;
  box-sizing: border-box;
  position: fixed;
  top: 0;
  z-index: 999;
  border: unset;

  width: 80px;
  height: 40px;
}

#collapseBtn:hover {
  background-color: gray;
}


.menu,
.content {
  width: 100%;
}

.menu {
  background-color: black;
  transition: height 0.8s ease-in;
  height: var(--height);
  overflow: hidden;
}

.content {
  background-color: burlywood;
  flex: 1;
  overflow: auto;
  margin: auto;
}

.menu-container {
  overflow-y: hidden;
  overflow-x: auto;

  height: 100%;
  width: 100%;

  position: absolute;
  bottom: 0;

  -webkit-transition: height 0.2s ease-in;
  -moz-transition: height 0.2s ease-in;
  -o-transition: height 0.2s ease-in;
  transition: height 0.2s ease-in;
}

.menu-container ul {
  background-color: #587c34;
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  height: 100%;
  padding: 1rem;
  box-sizing: border-box;
  overflow: auto;
  min-width: 100%;
  width: 100%;
  margin: auto;
}

.menu-container ul li {
  min-width: var(--height);
  border: 1px solid white;

  box-sizing: border-box;

  height: 100%;
  max-height: var(--height);
}

.menu-container ul li a {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0.2rem;
  box-sizing: border-box;
}

.menu-container .nav-link-container {
  display: flex;
  flex-direction: column;
  background-color: #f55858;
  justify-content: center;
  text-align: center;
  align-items: center;

...

 <div class="app">
      <div class="content">
        content
        <button id="collapseBtn" onclick="toggleCollapseMenu()">
          collapse
        </button>
      </div>
      <div id="mainMenu" class="menu">
        <div class="menu-container">
          <ul>
            <li>
              <a>
                <div class="nav-link-container">
                  <span class="nav-link-icon"><i class="fas fa-home"></i></span>
                  <span class="nav-link-text">One two</span>
                </div>
              </a>
            </li>

...

            <li>
              <a>
                <div class="nav-link-container">
                  <span class="nav-link-text">no icon</span>
                </div>
              </a>
            </li>
          </ul>
        </div>
      </div>
    </div>

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

Finding out the specific row that was clicked in a Jquery Mobile listview

I've searched everywhere and can't find a solution. How can I retrieve the value of a row tapped in a listview? This could be anything from the name to the index within the object. Currently, I have a function handling the tap event. I need to pa ...

Enhance the functionality of WordPress by applying additional parameters to all URLs

I'm currently working on theme development in WordPress and I want to showcase different color scheme variants to a potential customer. I discovered a tutorial that explains how to extract parameters from URLs and use them in my code. This allows me t ...

How come my counter is still at 0 even though I incremented it within the loop?

Within my HTML file, the code snippet below is present: <div id="userCount" class="number count-to" data-from="0" data-to="" data-speed="1000" data-fresh-interval="20"></div> In my Ja ...

What is the best way to calculate the width for each of the three elements in a row so that they all have 300px

Creating my own framework using flexbox has been an interesting journey. One of the major challenges I faced with flexbox is when dealing with an odd number of elements in a row, such as 3, 5, or 7. To tackle this issue, I decided to use JavaScript/jQuery. ...

What are the steps to customize the color of my navigation bar?

Currently, my website has a navigation bar with links that turn white after being clicked or visited, but I am struggling to make them white initially. Here is the code snippet for my HTML: <nav> <ul> <li><a href="index.html" ...

Incorporate a background image with the JavaScript CSS property

I'm having trouble adding a background image using the Javascript CSS property in my code. When I directly add the 'url', it works fine. Could the issue be with the 'weatherImage' variable? Javascript var OpenWeatherKey = ' ...

Enhancing dynamically generated elements with CSS styling

I have been working on developing my own jQuery Gallery Plugin. The crucial initial markup that is required to initialize the plugin includes: Initial HTML <div class="riGallery"> <ul> <li><a href="http://www.example.com" ...

Customizing error messages to display validation errors instead of default text errors in the Django UserCreationForm

I'm encountering an issue with the registration form on my website. The form itself is straightforward, but I'm facing a problem where if a username is already taken or if the two password fields don't match, Django doesn't respond afte ...

Obtain the contents of the table row td element within the specified div class without relying on

I am currently working with a basic table layout, shown below: <table> <tbody> <tr> <td>img</td> <td class="mediaTitle"><span class="media_title">Media Name Title</span>< ...

Are HTML attribute names really case-sensitive? A topic filled with conflicting information

After learning that attribute names are case-sensitive, I found conflicting information. A source mentioned that attribute names are indeed case-sensitive. For example, the width attributes in <div> and <DIV> would be considered separate due ...

What can be done to repair the gallery on this webpage?

Currently, I am experimenting with the Aria template, a free Bootstrap-based template. My goal is to utilize the gallery feature without any accompanying text. However, even after removing the text from the lightbox, the white background persists. What I s ...

What is the best way to access all sections of a JSON file containing nested objects within objects?

Here is an example of my JSON file structure: [{ "articles": [ { "1": { "sections": [ {"1": "Lots of stuff here."} ] } }, { "2": { "sections": [ {"1": "And some more text right here"} ] } } }] The c ...

Change the direction of the arrow on the button to point downwards once the menu has slid

After hovering over a button, an arrow is added to it. Upon clicking the button, a content div slides out within its wrapper by utilizing jQuery.slideToggle(). Following the slide out of the div, I aim to rotate the arrow in the button by 180 degrees to i ...

Ways to update images without having to reload the page following an ajax request

My current script uploads images to the server and updates the image source in HTML upon completion. However, I am facing an issue with my PHP code renaming the files to predefined names (ext-pix0.png, ext-pix1.png, etc.) during upload. This leads to the p ...

Reveal concealed roster using JavaScript

I am looking for a way to toggle the visibility of items in a list when an input is clicked. The challenge I'm facing is that the page should load with the list hidden, but the code only functions correctly if the list starts out visible. function ...

Verify if the input field is devoid of any content or not

I am planning to create a validation form using Vanilla JavaScript. However, I have encountered an issue. Specifically, I want to validate the 'entername' field first. If the user does not enter any letters in it, I would like to display the mess ...

The .remove() method is ineffective when used within an Ajax success function

I am facing an issue with removing HTML divs generated using jinja2 as shown below: {% for student in students %} <div class="item" id="{{ student.id }}_div"> <div class="right floated content"> <div class="negative ui button compa ...

What is the method for setting a video as the background of my div?

I've been trying to set a Youtube video as the background of my div. After researching online, I found that many people followed these steps: Welcome Easy to use. S ...

using CSS to create responsive designs with multiple divs

After spending hours searching, I am still struggling to get two divs to sit next to each other at 50% width each, with a third div below that spans 100% width. The challenge is to make the layout responsive, so that when the screen size is reduced to arou ...

Making a full-width browser bar by utilizing negative margins

I've been following a tutorial and need help with my header element. I want it to have a max-width of 800px and be centered in the middle of the page. Inside the header, there will be a #filtersBar div that spans the entire width of the page. Here&apo ...