Tips for aligning a div vertically at the bottom with overflow auto

I have some HTML code that looks like this:

<div class="ex">
<div class="ex0">
<div class="ex1">
 <div class="ex2">
 ....
 </div>
 <div class="ex3">
 ....
 </div>
</div>
</div>
</div>

ex0 is positioned absolutely, while ex1, ex2, and ex3 are relatively positioned. ex0 and ex1 have overflow set to auto. Additionally, ex1 has a minimum height of 480px and ex2 has a height of 100%.

I have two questions:

  • How can we ensure that ex3 is always aligned at the bottom of the ex1 div? I've tried using min height on ex2, but it's not the ideal solution as it distorts the boxes when viewing in flexbox or absolute position. Is there another way to achieve this alignment?
  • When I resize the window to a smaller height, the scrolling stops working properly. It gets stuck around one-quarter down the div. Any idea why this might be happening?

Below is the CSS for reference:

.ex {
   position: absolute;
   min-width: 1000px;
   min-height: 480px;
   left: 0px;
   right: 0px;
   top: 0px;
   bottom: 0px;
   z-index: 200;
   background: #262626;
}

.ex0 {
    box-sizing: border-box;
    position: absolute;
    display: block;
    width: 430px;
    right: 0px;
    top: 0px;
    bottom: 0px;
    padding: 0px;
    margin: 0px;
    border-left: 2.5px solid #1c1c1c;
    overflow: auto;
}

.ex1 {
  position: relative;
  height: 100%;
  padding: 52.5px 65px 40px 50px;
  overflow: auto;
}

.ex2 {
    min-height: calc(100% - 250px);
}

.ex3 {
   position: relative;
   width: 100%;
} 

Answer №1

Modify your "ex3" class as follows to adjust the positioning of the ex3 div for your initial question's response. This will ensure that the ex3 div appears at the bottom of the page.

.ex3 {
    position: absolute;
    bottom: 0;
} 

In regards to your second inquiry, a scroll bar appears on the browser screen when I implemented a demo using the HTML and CSS provided in the question. Additionally, when I resized the screen to a smaller height, the scroll bar remained visible on the page.

For further clarification, please refer to this jsfiddle link.

Answer №2

Replace .ex2 with .ex3:

.ex3 {position: absolute; width: 100%; bottom: 0;}

Ensure the scrollbar is functional!

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

How can I show a form and table on the same URL using Django?

Currently, I am delving into learning Django programming. I am in the process of creating a basic application that uses a form to update a referenced table. Everything was working fine until I decided to assign two different URLs for the table and forms. ...

Determining the Condition of a Hidden Field Value within ASPX Page Markup

Hey, I'm having trouble implementing an if condition in Markup because the Hidden Field is not accessible (error: Hidden Field doesn't exist in the current context). <asp:HiddenField runat="server" ID="hdpId" Value='<%# Eval("sId") %& ...

PayPal's fast checkout page experiencing a billing problem

I'm experiencing a problem with my paypal express checkout where it won't allow guest-checkout without logging into paypal, despite having the necessary form fields: <input type="hidden" name="SOLUTIONTYPE" value="Sole" /> ...

column with medium width of 4 is displaying oversized content

Hi there, I'm new to the forum and also to bootstrap. I have a problem with my layout that I can't quite describe (I am thinking in Spanish). Here's what's going on: I have three col-md-4 columns: the first column contains only text, w ...

Submitting a form using jQuery when the form is nested within a table

Why are forms not submitting with jQuery inside tables? I've tested form submission outside of a table and it works fine, but as soon as I wrap it inside a table, it stops working. I tried adding an extra parent() to adjust for the form moving above t ...

Singling out a particular navigation tab

When attempting to link specific table IDs so that the corresponding tab is active when opened (i.e. www.gohome.com/html#profile), I am facing an issue where the active tab remains unchanged. Even after specifically calling out tab IDs, there seems to be n ...

Combining numerous collapse toggles within a single navbar using Bootstrap

I'm just beginning to work on a new bootstrap site and I want the search bar to be part of a separate collapse toggle. I envision having the search bar toggle on the right side of the navbar, followed by the menu toggle. Here are my questions: How c ...

How to Vertically Align a div in the Center using Bootstrap 5

Is there a way to horizontally center a div using bootstrap 5? I want the div to be positioned in the middle, between the content above it and the end of the screen. I attempted the following: <div>some content</div> <div class="d-flex ...

Keeping DIV in place as page scrolls

My webpage has 2 columns, with the left column longer than the right one. As I scroll down the page, I want the right column to stay fixed in place while only the left column moves. This will ensure that the right column remains visible at all times rega ...

I am currently working with CakePHP and am interested in learning how to expire the admin session

I'm having issues with the code in my UserController. When I open the admin panel in two tabs within the same browser and log out from one tab, I am unable to redirect to the login page from the other tab when clicking on any menu. function beforeFil ...

Displaying database results in a text field

Whenever I establish a connection to my database and attempt to display its results in a text box, it fails to show anything beyond a space. For instance, as illustrated in the image below, only Brown is displayed while the rest is hidden. This issue arise ...

How can users of TinyMCE customize their background color?

I recently integrated iBrowser into my site's TinyMCE editor to allow users to upload graphics, which is working fine. However, I'm struggling to enable them to change the background image of the pages they are editing. Whenever I try adding a di ...

Selecting multiple elements with the same attribute value using jQuery

I am looking to target specific DOM elements using jQuery. Below is the HTML code: <li> <span class="node> <span class="con"></span> <span class="check"></span> <img> <a title="high">abc&l ...

Using either Java or Groovy, iterate through a hashmap and showcase an HTML table within a Velocity template

Just a heads up: Some users may have trouble reading code comments. For the record, this is not related to any homework assignment. I'm attempting to combine HTML and a hashmap for the first time. Despite searching for explanations online, nothing see ...

What are some ways to keep text within the boundaries of a div element?

I have tried multiple solutions for this issue, but none seem to be working for me. When I append a paragraph to a div, the text extends beyond the element. Below is the code I am using. Any assistance would be greatly appreciated. CSS: .chat-h { margi ...

Softly Transitioning Slideshow with Slide Effects

Has anyone had any experience with FlexSlider or jQuery in general? I've been using the FlexSlider slideshow script and I've made some customizations to fit my needs. You can check it out here: My main query is, does anyone know how to make the ...

jQuery Slider not appearing on the page

I am attempting to incorporate the Basic jQuery Slider into my website. Below is the code I have used: For HTML file: <div id="slides"> <ul class="bjqs"> <li><a href="somelink"><img src="someim ...

Center align a cropped image vertically within a div container

I am currently working on creating a CSS style that will allow me to scale an image to fit a letterbox-shaped div perfectly. The excess overflow will be cropped off, but I am encountering some issues with alignment. The current display can be seen here: h ...

Creating an HTML form that dynamically populates a second select dropdown from a MySQL database, depending on the value selected

How can I dynamically populate the second select input in my HTML Form based on the value selected in the first select input? <form action="hidden/add_training.php"> <select name="race_type" id="race_ ...

Ensure that the spinner div is horizontally centered within the side menu, even if a scroll

On my web page, I have a spinner component that can be added to different parts of the page as needed. The spinner is always centered according to its parent, which is in relative position, while the spinner itself is absolute. However, the issue arises wh ...