Chat box-style CSS utilizing flexbox techniques

I'm in need of creating a box with the use of flexbox for a chat interface.

However, I'm encountering some difficulties as it's not giving me the desired output.

.box{
width:350px;
  margin:10px auto;
  height:250px;
  border:1px solid #000;
  display:flex;
  flex-flow:column;
}
.header{
 border:1px solid blue;
 width:100%;
  flex: 0 1 auto;
}
.body{
 width:100%;
  flex: 1 1 auto;
  border:1px solid red;
  
  display:flex;
  flex-flow:column;
}
.scrollable{
flex: 1 1 auto;
  
  height:100px;
  overflow:auto;
}
.writebox{
flex: 1 1 auto;
  position:relative;
}
.writebox textarea{
height:100%;
  width:100%;
}
<div class="box">
  <div class="header">SOME CONTENT . Its fixed always</div>
  <div class="body">
    <div class="scrollable">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam luctus sapien lacus, vestibulum eleifend metus placerat at. Proin nec velit id orci lobortis feugiat. Phasellus cursus felis et imperdiet congue. In tincidunt vel urna eget venenatis. Ut libero velit, auctor non ipsum quis, interdum bibendum metus. Donec ut tempor nulla, sagittis volutpat magna. Donec ut ex fermentum, cursus lectus fringilla, vehicula quam. Morbi leo massa, rutrum non tortor eu, tristique mollis erat. Donec suscipit libero sit amet eleifend interdum. Quisque ut malesuada quam. Morbi interdum libero sed enim sodales rutrum.

Integer non metus vel tellus elementum auctor eu at lacus. Cras dapibus metus id purus porta, vitae fermentum mi imperdiet. Integer eget augue neque. Aenean varius lorem lectus, vitae lacinia nisl scelerisque et. Proin sed nibh aliquet, luctus elit sed, suscipit ligula. Morbi porttitor ligula eu risus varius, id hendrerit massa pharetra. Nullam nisl elit, sagittis nec libero non, tristique fermentum mauris. Phasellus posuere sem eu eros aliquam laoreet. Integer dui tellus, laoreet mollis nibh a, pretium finibus magna. Praesent quis convallis eros. Quisque pulvinar in sapien non dignissim. Praesent eu est nisl. Mauris sit amet nibh non nulla convallis sodales. Vestibulum porttitor dui vel nisl ultricies, non sollicitudin tortor imperdiet. Pellentesque vel nunc a est hendrerit accumsan non quis neque. Nam sagittis interdum elementum.</div>
    <div class="writebox"><textarea></textarea></div>
  </div>
</div>

This is what the current design resembles: https://i.sstatic.net/i2jOE.png

In my original code, the textarea has a variable height up to a certain limit x (I have integrated an autogrow plugin which is not included in this snippet)

Answer №1

Ensure that flex: 1 is applied only to elements with the class .scrollable, while making sure your .writable element functions as a flex container. Here's an example:

.scrollable {
  flex: 1;
}

.writeable {
  display: flex;
}

Take a look at the code snippet below (I've included the auto-grow plugin for textareas as well):

autosize($('textarea'));
.box{
width:350px;
  margin:10px auto;
  height:250px;
  border:1px solid #000;
  display:flex;
  flex-flow:column;
}
.header{
 border:1px solid blue;
 width:100%;
  flex: 0 1 auto;
}
.body{
 width:100%;
  flex: 1 1 auto;
  border:1px solid red;
  
  display:flex;
  flex-flow:column;
}
.scrollable{
  flex: 1;
  height:100px;
  overflow:auto;
}
.writebox{
  position:relative;
  display: flex;
}
.writebox textarea{
  height:100%;
  width:100%;
}
<div class="box">
  <div class="header">SOME CONTENT . Its fixed always</div>
  <div class="body">
    <div class="scrollable">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam luctus sapien lacus, vestibulum eleifend metus placerat at. Proin nec velit id orci lobortis feugiat. Phasellus cursus felis et imperdiet congue. In tincidunt vel urna eget venenatis. Ut libero velit, auctor non ipsum quis, interdum bibendum metus. Donec ut tempor nulla, sagittis volutpat magna. Donec ut ex fermentum, cursus lectus fringilla, vehicula quam. Morbi leo massa, rutrum non tortor eu, tristique mollis erat.</div>
    <div class="writebox"><textarea></textarea></div>
  </div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://www.jacklmoore.com/js/autosize.min.js"></script>

Hopefully, this information proves valuable!

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

When incorporating a CDN in an HTML file, an error message may appear stating that browserRouter is not defined

I am attempting to create a single HTML page with React and React-router-dom. Initially, I used unpkg.com to import the necessary libraries, and I was able to load the page with basic React components. However, when I tried incorporating React-router-dom ...

choose to display on mobile devices as a dropdown menu rather than a modal window

On mobile devices, my select elements are currently displayed as modals with options. However, I need to change this appearance to resemble the dropdown list view observed on desktop devices. Your assistance is greatly appreciated. ...

The Angular overlay panel remains open consistently

I recently developed an Angular component similar to p-overlaypanel, but I'm facing an issue where it remains open for every item I click. What I actually want is for only one overlay panel to be clicked and shown at a time - if I click on another ove ...

How can Chinese characters be transformed into XML/HTML-style numerical entities and converted into Unicode UTF-8 encoding?

I have a situation where I need to change a text that contains both English words and Chinese characters into a format that includes XML/HTML-style numerical entities for the Chinese characters. Here's an example of the original text: Title: 目录. ...

Tips on arranging radio buttons in a vertical layout with bootstrap

I am designing an exam system and I am trying to display the options per line. I attempted using display: block;, but it did not produce the desired result. Here is the snippet of my code. <div class="col-md-10"> <div class="box box-primary"& ...

Importing global variables in Angular SCSS files

Considering a transition to SCSS within my Angular project, I am primarily interested in utilizing the variables feature. Currently, I have been relying on CSS variables, which are conveniently declared in :root in my styles.css file and can be accessed in ...

What is the process for streaming video (images) to an HTML5 client using C#?

Currently, I am utilizing C# to fetch continuous bitmaps (video) from an ipcamera. These bitmaps are then converted to base64string and sent (JSON) to an HTML5 canvas, which is responsible for rendering the images. During my research, I came across a meth ...

Troubleshooting CSS Hover Not Displaying Properly in Angular 14

In the footer class of my HTML, there is a code snippet with chevrons: <div class="link-list"> <div *ngFor="let link of insideLinksLeft | originalOrderKeyValue" class="link"> <a [href]="link.val ...

Having difficulty retrieving a nested child element with querySelector in JavaScript

Encountering an issue with the querySelector method in JavaScript when accessing nested child elements. The goal is to retrieve the first child of a selected element and then obtain the first child of that inner element. Attempted code: let selected = doc ...

HTML snippet as implemented in Python

As someone who is new to Python and CGI, I have a question that may seem simple. I want Python to generate a block of HTML whenever a visitor loads a page. <html> <body> <!-- Beautiful website with great content --> <!-- Suddenly... ...

Creating an HTML table with collapsed borders and hidden rows/columns using the `border-collapse

I am facing a situation where I have a table with multiple lines as shown below: <table> <tr id="line1"><td>Line</td><td>1</td></tr> <tr id="line2"><td>Line</td><td>2</td></t ...

To prevent flickering when using child flex elements, it's best to use position fixed along with a dynamically updated scrollbar position using Javascript

My navigation component includes a slim banner that should hide upon scroll and a main-nav bar that should stick to the top of the screen and shrink when it does so. I initially looked into using Intersection Observer based on a popular answer found here: ...

The table dynamically adjusts based on the JSON data

My goal is to design a table that displays a JSON-object with multiple levels. The challenge is to showcase all the data in one row, even when it shows as [object object] like the Id in the plnkr example. ResultData=[ { "First_name": "xx", ...

Tips for eliminating the ripple effect when clicking on a q-list item

I have managed to create a sleek sidebar with a curved edge that seamlessly integrates into the body of the page. However, I am struggling to remove the semi-transparent ripple effect that appears when clicking on a list item. The current effect clashes ...

How can CSS be used to center multi-line text with the shortest line appearing at the top

I'm currently working on some html and css code that looks like this: <div style="width: 40em; text-align: center;"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard du ...

Is there a way to connect the YouTube iframe in order to display a pop-up message?

Is it possible to display popup messages when clicking on a YouTube video embedded in an iframe? <a href='login.html?sid=0&keepThis=true&TB_iframe=true&height=240&width=650' class="thickbox" title='test'> ...

Unable to open file:/// on localhost in the browser

I have been working on a website that can display the folders and files on a client's machine in an HTML table. Everything was functioning correctly, but I encountered an issue with creating href links for files on the client's machine which were ...

Guide to adding a Font to a server

Recently, I downloaded and installed a font on my computer and incorporated it into my project. While it appeared to work perfectly on my local system, I encountered issues when I uploaded the page to the server. How can I ensure that the font is properly ...

What is the best way to align my clip-path's text with the center of the viewport and ensure that all of the clip-path's text is visible?

Check out my React component demo: https://codesandbox.io/s/epic-brown-osiq1. I am currently utilizing the values of viewBox, getBBox, and getBoundingClientRect() to perform calculations for positioning elements. At the moment, I have hardcoded some values ...

Modify the class's height by utilizing props

Using Vue 3 and Bootstrap 5, I have a props named number which should receive integers from 1 to 10. My goal is to incorporate the number in my CSS scrollbar class, but so far it's not working as expected. There are no error messages, it just doesn&a ...