Tips for navigating through a div with an unknown height

I am currently working on developing a sleek messaging system and I have encountered an issue with the interface design. My project is built using Materialize, however, I am open to tweaking it with custom CSS if necessary. The layout consists of a list of messages on the left side, while the selected message is displayed in the remaining space on the right. This setup is quite standard.

The problem arises when there are numerous messages in the list or the text within the messages is too lengthy to fit within the viewing height without scrolling.

I strive for a non-scrollable page overall, but I also require the ability to scroll through the message list and view individually.

In my attempts to address this issue, I implemented the following CSS:

.message-view {
    height: 40vh;
    overflow-y: scroll;
}

While this approach somewhat works, it falls short of my desired outcome. What I truly aim for is the .message-view div to dynamically adjust its height to occupy the remaining space. Manually calculating heights based on preceding elements feels cumbersome to me and might not ensure precise heights across all devices.

TLDR: I seek a solution where a div can adapt its height dynamically to facilitate scrolling using either CSS or Materialize. Any suggestions?

Below is an illustration of the current dilemma (the list on the left is scrollable with a suboptimal height set arbitrarily at 80vh, along with the message view lacking scrolling functionality):

html, body {
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.content {
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: space-between;
}

.message-list-scroller {
  width: 30%;
  height: 80vh;
  overflow-y: scroll;
}

.message-list { 
  width: 98%;
  height: 100%;
  border: 1px solid gray;
}

.message-list-item {
  width: 100%;
  border-bottom: 1px solid gray;
}

.message-view {
  width: 70%;
  height: 100%;
  padding: 10px;
}
<html>

<body>

<h1>Message page</h1>

<div class="content">

  <div class="message-list-scroller">
  <div class="message-list">
    <div class="message-list-item">
      <h3>Title 1</h3>
      <p>Preview of the message</p>
    </div>
    <div class="message-list-item">
      <h3>Title 1</h3>
      <p>Preview of the message</p>
    </div>
    <div class="message-list-item">
      <h3>Title 1</h3>
      <p>Preview of the message</p>
    </div>
    <div class="message-list-item">
      <h3>Title 1</h3>
      <p>Preview of the message</p>
    </div>
    <div class="message-list-item">
      <h3>Title 1</h3>
      <p>Preview of the message</p>
    </div>
  </div>
  </div>
  
  <div class="message-view">
    <h2>Title</h2>
    <p>
    	Excessively long content...
    </p>
  </div>

</div>

</body>

</html>

Answer №1

Apologies for the blunt example provided - however:

1) Start by creating a page container with a height of 100vh and set the overflow to hidden.

2) Utilize the grid system to establish two columns, also setting their height to 100vh.

3) Within these columns, insert a .scrollable div with a maximum height of 100vh.

<div class="messages">
  <div class="row">
    <div class="col m4">
      <ul class="scrollable">...</ul>     
    </div>
    <div class="col m8">
      <div class="scrollable">...</div>
    </div>
  </div>
</div>

.messages {
  height:100vh;
  background-color: silver;
  overflow: hidden;
}

.col.m4 {
  background-color: white;
}

.col.m8, col.m4 {
  height:100vh;
}

.scrollable {
  max-height:100vh;
  overflow:hidden;
  overflow-y:scroll;
  padding-bottom:20px;
}

View on Codepen.

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

Refresh a function following modifications to an array (such as exchanging values)

Looking to re-render a function after swapping array values, but the useEffect hook is not triggering it. I need assistance with this as I plan to integrate this code into my main project. Below are the JSX and CSS files attached. In App.js, I am creating ...

What is the best way to allow text input in a table cell to exceed the confines of the table when it is clicked on

I am currently working on a table that has three columns: a label, a dropdown selector, and an input field. The challenge I'm facing is that the input field needs to accommodate multiple lines of content, specifically in JSON format. However, I want ...

The arrow extends just a hair below the boundaries of the div, by approximately 1 pixel

I am facing an issue with my nav bar code. In Firefox and Chrome, everything works perfectly fine - there is a small arrow displayed below the links when hovered over. However, in Internet Explorer, the arrow appears slightly below the div, causing only pa ...

Automated vertical alignment of rows within the Bootstrap table

I'm currently working on a table for my personal project that populates with data from the database. I am trying to get the rows to display vertically under headings (see screenshot at the bottom of this question). I have attempted various solutions f ...

Clicking on the input triggers the appearance of a border using the OnClick function

I am currently developing my own website with a login feature that requires input tags of text-type. I would like to implement a functionality where clicking on these input tags will display a border, even when the mouse is not directly hovering over them. ...

What steps should be followed to effectively incorporate Google Fonts into a Material UI custom theme for typography in a React/TypeScript project

Hey there, I'm currently working on incorporating Google fonts into a custom Material UI theme as the global font. However, I'm facing an issue where the font-weight setting is not being applied. It seems to only display the normal weight of 400. ...

Ways to recover HTML elements that have been eliminated by jQuery's remove

$(document).ready(function() { $('#remove').click(function() { $('.test').remove(); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="test-wra ...

What's the best way to adjust the card column for mobile view resizing?

I am trying to modify the card view for mobile devices to display as a 2-column layout. I have adjusted the flex length and grid size in my code, but I still can't achieve the desired result. Can someone guide me on how to make this change? Current d ...

The scaling feature in CSS does not function properly in Internet Explorer 8

I've tried multiple approaches to transform the IE Matrix, but I'm facing an issue with the transform scale CSS not functioning in IE8. Code: .fture_box ul li.fture_img img{ width: 451px; height: 284px; display: block; margin: 0 0px 0 11px; pad ...

Step by step guide on incorporating two background images in a single header

I'm looking to create a header with a background image that appears twice, like this: To achieve the effect, I added opacity of 0.5 to one of the images, but it is affecting everything in my header including text and logo. Is there a way to prevent t ...

What is the best way to use ajax to load a particular div or class from a file?

In my main.html file, there are several divs each with 2 classes. The first is their specific class and the second is a class called menu-item, which determines if an event will be triggered when clicked. For example: <div id="load-here"> </div ...

How can I implement a thumbnail editing feature similar to Facebook's display image uploader in an Asp.net application using c#?

How can I upload an image and display a specific part of it in a thumbnail of a custom size? I also want to personalize the appearance of the thumbnail. ...

Optimal method for arranging Vue components

When deciding where to position a child element, should it be done within its own CSS scope or from the parent? In the scenario provided below, would it be more effective to use margin-left: auto; on the parent element or the child element (both options a ...

Excess space located adjacent to primary content on website

When you scroll to the left of the page, next to the main content and outside of the browser width, there is additional space occupied only by the background of the Body CSS. Take a look at the site in action: . @charset "utf-8"; /* Custom CSS Styles * ...

A sporadic glitch in IE10 appears while attempting to translate text with a border-radius feature

I need some advice regarding a rendering issue I am experiencing in IE10. I have created an animated-flip effect that works perfectly in all the browsers I need it to. However, during testing, I noticed random border-like lines appearing for no apparent re ...

Tips for centering a paragraph vertically within a div element

I'm struggling to achieve automatic vertical alignment for this. While I can manually center it using padding-bottom, I prefer a way to position it vertically on its own. How can I accomplish this while retaining the display: inline-block feature? &l ...

Tips for adjusting the font size of a Chip using Material-UI

I am using a widget called Chip const styles = { root:{ }, chip:{ margin: "2px", padding: "2px" } } const SmartTagChip = (props) =>{ const classes = useStyles(); return( <Chip style={{color:"white&q ...

How can I alter the color of the menu text when scrolling to the top of a webpage?

As I navigate my website, I encounter a menu with a transparent background at the top that changes to black as I scroll down. On a specific page where the background is white, this presents an issue: when the menu reaches the top, the white background clas ...

Setting a fixed width for the body element results in alignment problems

I'm struggling with aligning divs properly on my HTML page that has a tab using CSS and jQuery. Whenever I try to set a fixed width for the body or main container, everything goes out of place... How can I ensure that the body has a minimum fixed widt ...

CrossBrowser - Obtain CSS color information

I'm attempting to retrieve the background color of an element: var bgcolor = $('.myclass').first().css('background-color') and then convert it to hex function rgbhex(color) { return "#" + $.map(color.match(/\b(\d+ ...