Excessive text overflowing in a chat interface can be resolved through CSS styling

After conducting a thorough search, it appears that very few individuals are taking this important element into consideration. I currently have a chat interface set up with a div element containing a ul, which then houses li elements that contain p elements.

Below is the HTML code for reference:

.chatRight {
  background-color: lightgrey;
  font-size: 30px;
  padding: 5px;
  border-radius: 6px;
  max-width: 50%;
  word-wrap: break-word;
  text-align: right;
  margin-left: auto;
  display: table;
}
.chatLeft {
  background-color: aqua;
  font-size: 40px;
  padding: 5px;
  border-radius: 6px;
  max-width: 60%;
  word-wrap: break-word;
}
.chatBoxRight {
  text-align: right;
  word-wrap: break-word;
}
.chatBoxLeft {
  text-align: left;
  word-wrap: break-word;
}
#chatList {
  width: calc(100% - 80px);
  list-style-type: none;
  max-width: calc(100% - 80px);
}
#chatList li {
  margin-top: 5px;
  margin-bottom: 5px;
}
<div id="chatContainer">
  <ul id="chatList">
    <li class="chatBoxLeft">
      <p class="chatLeft">Hello there!</p>
    </li>
    <li class="chatBoxRight">
      <p class="chatRight">Good day</p>
    </li>
    <li class="chatBoxLeft">
      <p class="chatLeft">How do you do?</p>
    </li>
    <li class="chatBoxRight">
      <p class="chatRight">hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhaaaaaaaaaaaaaaa</p>
    </li>
    <li class="chatBoxRight">
      <p class="chatRight">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
    </li>
  </ul>
</div>

The issue at hand is the overflowing content, where everything looks fine except for the extended "aaa..." text causing the rounded container to overflow. This problem highlights an issue not only with the excessive text but also with the max-width property not functioning as expected in certain scenarios.

(Just for demonstration purposes, I included the display:table for the right-box paragraph elements).

I appreciate any assistance or suggestions you can provide regarding this matter.

Answer №2

Try either removing the display: table; property from the .chatRight class, or replacing it with word-break: break-all; instead of word-wrap: break-word;

.chatRight {
  background-color: lightgrey;
  font-size: 30px;
  padding: 5px;
  border-radius: 6px;
  max-width: 50%;
  word-wrap: break-word;
  text-align: right;
  margin-left: auto;
}
.chatLeft {
  background-color: aqua;
  font-size: 40px;
  padding: 5px;
  border-radius: 6px;
  max-width: 60%;
  word-wrap: break-word;
}
.chatBoxRight {
  text-align: right;
  word-wrap: break-word;
}
.chatBoxLeft {
  text-align: left;
  word-wrap: break-word;
}
#chatList {
  width: calc(100% - 80px);
  list-style-type: none;
  max-width: calc(100% - 80px);
}
#chatList li {
  margin-top: 5px;
  margin-bottom: 5px;
}
<div id="chatContainer">
  <ul id="chatList">
    <li class="chatBoxLeft">
      <p class="chatLeft">Greetings!</p>
    </li>
    <li class="chatBoxRight">
      <p class="chatRight">Good evening</p>
    </li>
    <li class="chatBoxLeft">
      <p class="chatLeft">How are you?</p>
    </li>
    <li class="chatBoxRight">
      <p class="chatRight">hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhaaaaaaaaaaaaaaa</p>
    </li>
    <li class="chatBoxRight">
      <p class="chatRight">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
    </li>
  </ul>
</div>

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

Create shortened class names

Is there a way to abbreviate class names in HTML and CSS files? For example, I currently have the class name: .profile-author-name-upper And I would like to change it to something shorter like: .p-a-n-u or .panu Any suggestions on how to achieve thi ...

I kindly request your assistance in resolving the issues with the append() and empty

Here is some code I've been working on: <!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function(){ ...

Creating an attention-grabbing alert bar positioned above the menu

When I attempted to add this alert bar to my website, I encountered an issue where it was being hidden behind my menu. Some sources suggest that using z-index and position:absolute can resolve this problem by positioning one element above the other, but th ...

Creating elegant Select Dropdown Box in AngularJS without relying on images

I am currently working on an angular page and have implemented a dropdown with ng-Options to fetch and set values successfully. However, I am now looking to enhance the appearance of this dropdown. After exploring options like ui-select, I realized that be ...

Displaying data from a JSON object to a DOM table can be achieved by dynamically generating table columns based on the keys within

There is a JSON object that I'm working with: [ { "SysID": "4", "Defect Classification": "Wrong Image Color", "1": "3.0", "2": "", "3": " ...

Display React elements on the web page

Seeking assistance from anyone! I've been grappling with a problem and can't seem to figure out a solution. Here's the scenario: My current setup involves a sidebar and a top bar for navigation in React. Check out my app so far in this imag ...

Navigating a series of HTTP requests with VBA and saving the retrieved data in Excel 2010

I have a total of 5 Excel files that I currently use with WinHttpRequest to extract data into them. My goal is to consolidate all the requests into a single VBA script, loop through them, and store the data sequentially on one sheet. However, I am facing ...

Locate grandchildren elements using getElementById

My task is to modify the content and attributes of the table. The DOM structure is generated by a third-party tool, and I am using JavaScript to make changes in various sections. <div id="myId"> <div> <div> <table&g ...

Quiz timer using JavaScript

In my HTML and JavaScript project, I am creating a quiz game where players have 15 seconds to answer each question. To implement this timer feature, I used the following code snippet: <body onload="setTimeout(Timer,15000)"> Implemented in JavaScrip ...

Implement a versatile Bootstrap 5 carousel featuring numerous sliders

Is it possible to create a Bootstrap 5 carousel with six items displaying at a time instead of three? I tried changing the value in the JS code, but it didn't work. Can you correct my code so that it displays six items at a time and can be variable la ...

Modify the title attribute within a span tag in PHP using AJAX

I'm currently working with Zend Framework 2 and I have a requirement to translate a string in my index.html file, which displays a tool tip when hovering over a span tag. The challenge I face is that this value needs to change dynamically after perfor ...

Tips for storing form information using Flask and Vue.js

Currently, I am tackling a straightforward assignment that requires me to utilize tools with which I am not very familiar. In this task, I need to find a way to save the form data (preferably to a text file as the optimal solution) or at least serialize it ...

The drop-down menu auto-loads as though it is being hovered over

I recently added a drop-down menu to my website that includes social media buttons. All the buttons are working properly, except for Google+. When the page loads, it seems as though the hover effect is automatically activated for the Google+ button. For e ...

Creating interactive labels in a histogram that update based on the user's input

Currently, I have operational code in place that takes input data and generates a histogram based on set thresholds. When the code is executed, the histogram changes dynamically as the threshold slider is adjusted. However, there seems to be an issue wit ...

Display a dropdown menu when clicking on a close button in a single element using Vanilla JavaScript

I'm currently in the process of learning Javascript and trying to grasp the concept of events and selectors. My aim is to have a close button that, when clicked, triggers a specific dropdown related to the card it's attached to. I plan to achie ...

Would parallax stars be overwhelming for a webpage?

I'm a newcomer to the world of web development and I have an idea to make stars move across my website. However, I'm concerned about whether this might be too much for a simple website to handle. Is there a way to optimize the code? const canvas ...

Need help positioning this HTML iframe on my webpage?

Can anyone help me figure out how to position this HTML i-frame in a specific place on my webpage? <div style="overflow: hidden; width: 333px; height: 156px; position src="h: relative;" id="i_div"><iframe name="i_frame"http://url.com/click.php?a ...

What is the best way to set the background opacity to 0.7 without impacting the content within it?

Currently, I'm facing an issue with two divs - the outer one is identified as "BD" and the inner one as "content". Whenever I attempt to reduce the opacity of BD's background-color, the content inside also becomes less opaque including both image ...

Retrieving data from a <span> element within a webpage created using ReactJS

I am completely new to the world of web design and development, so there may be some mistakes in my request. Essentially, I have a webpage that contains numerous span tags like the following example: These span tags are part of a significantly large DOM t ...

I am eager to run the code that I retrieved from the server. I have access to the code in my console and I desire for it to execute on the main browser page

Currently, I have a simple Google Chrome Extension that includes a button. By using AJAX, I am fetching a script from a server in my browser's console. Essentially, clicking on the extension reveals a button which, when clicked, fetches the script fro ...