Setting the CSS property `overflow-y: scroll;` does not make the element scrollable and causes it to exceed 100% of the block

I am seeking a solution to create a y-axis scrollable block within the left-navbar. The height of this block should occupy all available space within the left-navbar, ensuring that the left-navbar itself remains at 100% of the page height.

The issue arises when the history overflow is not scrollable, causing all history-item elements to be displayed and consequently increasing the height of the left-navbar beyond the page height.

Furthermore, as the page height reduces, the history-overflow should only fill the free space to prevent the left-navbar from exceeding 100% of the page height. How can this be achieved?

Check out the Codepen sandbox example for reference: https://codepen.io/car1ot/pen/zYqLqKB

HTML code:

<div className="left-navbar">
    <div className="history">
        <label>History</label>
        <div className="history-overflow">
            <div className="history-item">*...some content here...*</div>
            *...more history-item(s) here...*
        </div>
    </div>
</div>

CSS (scss) code:

div.left-navbar {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 290px;
    height: 100%;
    padding: 25px 20px;
    box-sizing: border-box;

    div.history {
        display: flex;
        flex-direction: column;

        div.history-overflow {
            margin-top: 8px;
            margin-right: -20px;
            padding-right: 14px;
            overflow-y: scroll;

            div.history-item {
                display: flex;
                align-items: center;
                flex-shrink: 0;
                padding: 0 16px 0 6px;
                height: 40px;
                width: 100%;
                border-radius: 7px;
                margin-bottom: 8px;
                box-sizing: border-box;
            }
        }
    }
}

Answer №1

To achieve the desired effect, consider applying overflow: hidden to the element with the class .history and setting max-height: 100vh on the element with the class .left-navbar. This should meet your requirements, although you may need to adjust the specific values based on your overall layout. The key is to establish a height limit in order to control the display.

Answer №2

If I understand correctly, this seems to be your proposed solution:

body { padding:0; margin:0; }

div.left-navbar {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 290px;
    height: 100vh;  /* Defined */
    padding: 25px 20px;
    box-sizing: border-box;
    background: rgba(#000, 0.1);

    div.history {
        display: flex;
        flex-direction: column;
        height:100%;  /* Defined */
        div.history-overflow {
            margin-top: 8px;
            margin-right: -20px;
            padding-right: 14px;
            background: rgba(blue, 0.1);
            overflow-y:scroll;
            div.history-item {
                display: flex;
                align-items: center;
                padding: 0 16px 0 6px;
                height: 100px;
                width: 100%;
                border-radius: 7px;
                margin-bottom: 8px;
                box-sizing: border-box;
                background: rgba(#000, 0.075);
            }
        }
    }
  }

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

Different ways to swap table cells using only CSS

Does anyone know how to switch the positions of table cells using only CSS? I have three divs set up like this: #content { width: 1000px; display: table; float: none; vertical-align: top; border: 1px solid red; } #left { float: left; } #ri ...

What is the best way to display an image right in the middle of the header?

My project consists of three main files - an HTML, a CSS, and a JS file. I have developed the HTML using the Bootstrap 5.1.3 framework. The issue I am facing pertains to the alignment of the clothing brand logo within the header section. Despite multiple ...

Converting JavaScript variable values to PHP variables by extracting the content of a textarea

Currently, I'm developing a data filtering mask which triggers when the button <input type="button" /> is clicked. In this process, I have: School classes (1, 2, 3, 4, 5) Sections (A, B, C....Z) Checkboxes for male and female sexes. This ma ...

Issue with Bootstrap 4 columns overlapping upon screen resizing

Whenever I use a row with 4 columns within a container that has 3 columns, the text file overlaps with the column containing an image when the screen size is reduced or viewed on an iPhone. Take a look at the code snippet and screen capture provided below ...

Struggling to make JavaScript read JSON data from an HTML file

I am currently working on developing a word search game using django. One of the tasks I need to accomplish is checking whether the entered word exists in a dictionary. To achieve this, I have been converting a python dictionary into JSON format with json. ...

Is there a definitive way to distinguish between scrollTop and scrollHeight in web development?

For instance, function checkingScroll(){ var newHeight = element.scrollHeight; var scrollTopValue = element.scrollTop; alert("The scrollHeight property is: " + newHeight + "px"); alert("The scrollTop property is: " + scrollTopValue ...

New programmer seeking to apply a dim effect to the entire photo while also adding a highlight when the image is hovered over

I am looking to add a special effect to my photos where they appear dimmed but highlighted when hovered over. Any guidance on how to achieve this would be greatly appreciated! The image is contained within a flexbox div that also contains a clickable lin ...

Ways to Export HTML to Document without any borders or colorful text

How can I make a contentEditable area visible when filling text and then disappear when exporting the document? I found a script online that allows you to do this, but the issue is that the contentEditable area is not visible until clicked on. To address t ...

Looping through PHP code to encapsulate HTML elements

As a newcomer to PHP, I appreciate your patience as I navigate this new language. My goal is to wrap a div around elements like the "h4" tag without disrupting the for loop. Is this achievable? Thank you. <?php $con=mysqli_connect("localhost","root"," ...

Sharing a document that contains a linked image file using a relative path through the `publish` feature

I have reviewed the documentation and tested the steps provided in this example, but I am still unable to find a solution for the issue at hand. Based on the documentation, the image file should either be located in the same path as the MATLAB script bein ...

A guide to customizing nested elements in react using styled-components

Currently, I am utilizing styled components to apply styles to a child element inside a div using nested css. For a demonstration, you can view my example here const customStyles = theme => ({ root: { ...theme.typography.button, background ...

Postback does not show updates made by JQuery

On Page_Load, I have two asp:BulletedLists - one is already filled with data while the other remains empty. Users have the ability to drag and drop <li>'s between these lists using the following function: function Move(element, source, target) { ...

What is the best way to add color to the bottle's outline using clipPath?

How do I fill the background inside a bottle image with color? I have the coordinates for filling the bottle, but the background inside remains unfilled. .item { width: 150px; height: 150px; } #tubeLiquid { background-color: #74ccf4; clip-path ...

Navigating Back to the Previous Page After Accepting an Alert Popup in Selenium

My testing process involves using Selenium with Python on a test page. Here is what happens during the test: First, I have page A open and then I click on a link that triggers the opening of page B. Upon submitting a form on page B, an alert popup ap ...

The slideshow feature on W3 Schools does not start automatically when the page loads

After following the W3Schools tutorial to create a slideshow, I found that the animations are working correctly. However, only three dots appear on the screen and I have to manually click on one of them to view the pictures. var slideIndex = 0; sh ...

Using Angular2, you can dynamically assign values to data-* attributes

In my project, I am looking to create a component that can display different icons based on input. The format required by the icon framework is as follows: <span class="icon icon-generic" data-icon="B"></span> The data-icon="B" attribute sp ...

Verify whether the content within the Div has been modified

I am currently making changes to content within a <div> element. I would like to determine if the data in the <div> has been modified and, if so, save it in a session to persist on refresh. How can I verify if the data has been edited and then ...

Trouble aligning Material UI data-table columns (table head) to center in React

I have a data table where I declare rows and columns as simple variables, making it difficult to style them using 'style={{textAlign: center}}'. I tried adding a CSS file, but it did not work with the Material UI table. I am unsure of how to proc ...

Tips for designing a horizontal sub-navigation menu using CSS?

I have limited experience with list menus and am struggling to create a horizontal submenu with its own styling. Despite multiple attempts, I have been unsuccessful in finding a solution and have put the project on hold for now. Here is what I currently h ...

AInspector WCAG evaluation found that mat-select does not meet level A compliance standards

As I work on making my website WCAG level A compliant, I've encountered an issue with the mat-select component in Angular material. After running checks with the AInspector extension for Firefox, it appears that the mat-select component lacks aria-con ...