What is the best way to align these DIVs vertically using CSS?

Working on a code snippet:

#contains_upper_and_lower_panes {
  overflow: hidden;
  overflow-y: hidden;
  overflow-x: hidden;
  background: white;
  margin-top: -113px; /* shifting up to cover up something above the container */
  height: 100%;
  width: 45rem;
}

.halfPane {
  width: 100%;
  overflow-x: hidden;
  overflow-y: scroll;
  height:50%;
}
<div id="contains_upper_and_lower_panes">

  <div id="upper_pane" class="halfPane">
    <h3>top</h3>
    <p>paragraph</p>
    <p>paragraph</p>
    <p>paragraph</p>
    <p>paragraph</p>
    <p>paragraph</p>
    <p>paragraph</p>
  </div>

  <div id="lower_pane" class="halfPane">
    <h3>bottom</h3>
    <p>paragraph</p>
    <p>paragraph</p>
    <p>paragraph</p>
    <p>paragraph</p>
    <p>paragraph</p>
    <p>paragraph</p>
  </div>
</div>

... and this works great as long as there aren't too many paragraphs.

However, if you double the number of paragraphs in either/both section, suddenly the container div shows a scrollbar and the height of both of the panes gets larger than 50% (and they each also show a scrollbar).

The aim is for the outer container to never show a scrollbar, while the upper and lower panes STAY at 50% height, and each show a scrollbar when necessary.

What am I doing wrong here?

Answer №1

To ensure that #contains_upper_and_lower_panes fills the entire screen on any device, set its height to 100vh. This will allow the height: 50% property in the half pane class to work effectively.

#contains_upper_and_lower_panes {
  overflow: hidden;
  overflow-y: hidden;
  overflow-x: hidden;
  background: white;
  margin-top: -113px; 

/* Change the line below */
  height: 100vh;

  width: 45rem;
}

You can then adjust the height or width of the half pane for optimal results.

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 best method for importing data into an array using AngularJS?

Check out the Plunker link I have shared. Can you help me identify any mistakes? <a href="https://plnkr.co/edit/3VryaPGtgPRD6Nn8zx7v">Click here to visit the Plunker page</a> ...

transforming a div container into an inline element using CSS

Hey there! I'm facing an issue with CSS where I am trying to change a div tag into inline. <div id="menu1"> <ul> <a href="#"> <li> one</li> </a> <a href="#"> <li> two</li> </a> <a h ...

How can you make a floating div shift below a non-floating table rather than resizing when there is limited space available?

My layout consists of a div and a table displayed side-by-side: <div style="float:right ...">Contents</div> <table>contents</table> I am looking for a solution to make the div move below the table when there is not enough space to ...

Dynamic Design with Pure CSS

I am in the process of creating a flexible layout design. Everything appears to be functioning as intended on FF, Chrome, Safari and IE8 However, I have encountered an issue with IE7. It seems to be related to the floated containers. I have attempted a fe ...

Unable to get CSS transition to function properly after adding a class using jQuery

I am trying to create a hover effect that shows an image when the mouse is over a specific div, but for some reason, the transition is not working as expected. I understand that using visibility: hidden cannot be animated. Here is the code snippet: $(d ...

ngx hierarchical dropdown

Is it possible that the 'disabled' attribute is not a recognized property of the 'ngx-dropdown-treeview' component? The ngxDisabledOnSelector property seems to be malfunctioning in my specific case. This is my code snippet: <ngx-dr ...

Modifying app aesthetics on-the-fly in Angular

I am currently working on implementing various color schemes to customize our app, and I want Angular to dynamically apply one based on user preferences. In our scenario, the UI will be accessed by multiple clients, each with their own preferred color sch ...

Exploring the functionality of buttons within jQuery Impromptu

My current project involves creating a survey composition tool. The main focus is on having a preview button that displays the values inputted by the user. <!doctype html> <html> <head> &l ...

:host background color may be missing, but the font size has been boosted?

Check out this demo where the CSS is applied to the :host element or <hello>. The font size increases but the background color remains unchanged. What do you think? styles: [` :host { font-size: 2rem; background-color: yellow; }`] }) ...

Tips for personalizing the WordPress menu options located in the header

After creating a WordPress menu and displaying it in the header with a total of 6 pages or menu items, I now want to split the menu so that 3 items appear on the left side and the other 3 on the right. However, my lack of knowledge in stylesheet styling ...

"Track the progress of a form submission with a loading indicator using Sweet

I am looking to incorporate a waiting time animation when submitting a form, and I prefer using SweetAlert over a traditional loading image. Here is the basic code snippet: $("form").submit(function (e) { e.preventDefault(); // prevents def ...

Can a hyperlink open multiple links at the same time when hovered over?

Can two links be opened in the same hyperlink when hovered over? ...

The UL list has a first list item that is being indented

While working on my Magento 1.9.x website, I noticed a strange issue with the product descriptions. The bulleted lists are displaying fine, except for the first bullet point which is indented more than the rest of the list. Below is the code snippet I am ...

Implementing a CSS codepen within a React Material-UI component

I'm struggling to implement this effect on my material ui card component using react and makeStyles. I am having difficulty translating this effect to the cards, could someone assist me in simplifying it into a CSS code that can be used in MakeStyles? ...

Utilizing jQuery for a dynamic sliding effect: using the animate function to shift text horizontally based on a percentage of the

I'm brand new to jQuery and seeking to create a simple animation example. I want the animation to be percentage-based in order to accommodate various screen sizes. Here is the initial jQuery code I tried: $(document).ready(function() { $('# ...

Checkbox fails to activate menu when selected

I am currently working on a responsive navbar that transforms into a hamburger icon for mobile devices. I implemented media queries to detect mobile devices and display a hamburger icon. Subsequently, I created a mobile menu that appears and disappears whe ...

Retrieve the value of a data attribute from a button when it is clicked

I am struggling to display the information from <div id="data"> <button data-toggle="modal" data-toggle="tooltip" data-placement="top" style="margin:5px; data-SenEmail="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemai ...

What is the best way to evenly distribute dynamic divs in a vertical layout?

Essentially, my goal is to have the child divs evenly spread out within the parent div. If one of the child divs is removed, I want the remaining divs to resize and fill the space equally again. For example: ---parent--------------- | ----------------- ...

Click to trigger image rotation with JavaScript

img { display: block; margin: 20px; width: 50px; height: 50px; } .crossRotate { -webkit-transition-duration: 1s; -moz-transition-duration: 1s; -o-transition-duration: 1s; transition-duration: 1s; -webkit-transition-property: -webkit-tran ...

Verify the existence of the linked page's href url

Is there an elegant way to verify if a hyperlink on a website directs to a page that returns an HTML 200 code? I'd like to give users the ability to input their own links in a model, but I also want to block any links leading to a 500 or 404 error pag ...