Arrange the text in a div element in a horizontal direction

While developing a friends list script for a website, I encountered an interesting UI issue in the chat section. When a lengthy chat message is added to the chat content div with the CSS attribute overflow: scroll, it causes the div to stretch out horizontally like this:

https://i.stack.imgur.com/5DAMB.png

To prevent this from happening, I want to ensure that the <p> tags within the content div wrap to the next line when they exceed the width of the content div. Currently, my CSS code looks like this:

#chatContentDiv {
    height: 70%;
    width: 100%;
    overflow: scroll;
    background: rgba(0, 0, 75, 0.3);
    text-align: left;
}

#chatContentDiv p {
    font-size: medium;
    width: 100%;
    padding: 10px;
    margin: 0;
}

Is there a way to achieve this without compromising the scrollability of the chat content div? I want to avoid horizontal extension when a message contains very long words.

Answer №1

Why not give this a shot...

Implement the word-wrap attribute to handle long words that exceed the container's width

#messagesContainer p {
    font-size: medium;
    width: 100%;
    word-wrap: break-word;
    padding: 10px;
    margin: 0;
}

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 causes variations in the output of getClientRects() for identical code snippets?

Here is the code snippet provided. If you click on "Run code snippet" button, you will see the output: 1 - p.getClientRects().length 2 - span.getClientRects().length However, if you expand the snippet first and then run it, you will notice a slight dif ...

jQuery concealing selections from dropdown menus

Is there a way to use jquery sort to order dropdown list options and hide the "select" item in the dropdown? Check out my fiddle code here <select id="mySelect"> <option value="">select</option> <option value="1">a</opt ...

Tips for adjusting the time format within Ionic 3 using TypeScript

I currently have a time displayed as 15:12:00 (HH:MM:SS) format. I am looking to convert this into the (3.12 PM) format. <p class="headings" display-format="HH:mm" > <b>Time :</b> {{this.starttime}} </p> In my TypeScript code t ...

Convert a fixed Jquery div to absolute positioning when it reaches the end of the page

I've implemented a Jquery code that adds a fixed class to a div when scrolling down. However, I now want to remove this fixed class when it reaches the bottom of the page and replace it with a new one that includes position:absolute; and margin-bottom ...

Can a variable containing HTML code be iterated through with a loop?

I am currently working on setting up a select button that will receive options from an ajax call. The ajax call is functioning properly. However, I am facing a challenge when trying to create a variable containing the HTML. I am unsure of how to iterate a ...

Designs for Creating Webpages

As a beginner in the coding world, I have little experience with HTML and Python. My goal is to create a personal webpage, starting with a template and customizing it to fit my needs. Any suggestions on where to find free templates or where to begin my s ...

Attempting to conceal an HTML 'label' element by employing CSS 'hide' properties

Why is it so difficult to hide a checkbox that says "Remember Me" on my membership site login form? The HTML code snippet causing the issue: <label><input name="rememberme" type="checkbox" id="rememberme" value="forever" /> Remember Me</la ...

Display or conceal <ul>'s using JavaScript when the mouse enters or leaves

I'm encountering an issue with a basic JavaScript function. The goal is to toggle the dropdown menu on my website when the mouse hovers over or leaves the menu. The problem arises because my script is triggered by the ul tags within my menu, and I ha ...

Issue with jQuery: Changes are not being triggered and clicks are also not working

I managed to recreate the modifications of my complex script in a simple jsfiddle, which can be found here. Below is the code I am working with locally: HTML <input type="text" id="rangeStart" value="updateMe" /><br/> <input type="text" c ...

Error Message Design in ASP.NET

I am currently developing a website using .net, which is a new technology for me. Here is the snippet of code I am working with... <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ValidationGroup="V1" Display="Dynamic" ...

Removing a CSS Class Using Tampermonkey: A Step-by-Step Guide

I'm completely new to CSS and javascript, so please bear with me. My goal is to remove the class disable-stream from each of the div elements located under the div with the class "stream-notifications". Below is an image for reference: Even though I ...

Achieving perfect alignment both horizontally and vertically using CSS3's viewport height of 100%

I'm trying to utilize CSS3's Viewport Height to create a fullscreen section with a height of 100vh. However, I am encountering difficulties in centering elements both horizontally and vertically within the section. My goal is to have an image and ...

JavaScript Navigation Bar Error: The value of 'undefined' is not recognized as an object

Having just started learning HTML, CSS, and JavaScript, I encountered an error message that reads: TypeError: 'undefined' is not an object. Despite my best efforts to troubleshoot the issue, I have been unable to resolve it. Is there anyone who c ...

How to fetch select element within a table by using jQuery

I encountered a situation where I have a table element with a select element inside its td. The id of the table (in this example, it is "table1") could potentially change. So my query is, how can I retrieve the selected option using the table ID in JQuer ...

What is the most effective method to horizontally center a div element when its width and height are not predetermined

Let's say there is a div element on the page like this: <div class="center"></div> The CSS style for this div may look something like this: .center{ background:red; position:absolute; left:50%; top:50%; margin-left: ...

Obtaining the weight of a webpage using Selenium Automation_Framework

Currently, I am in the process of creating performance-related tools for web pages within a Selenium framework designed for .NET systems. With a focus on page performance, I am specifically analyzing page load time and page weight. In order to measure th ...

The alignment of SVG is not in sync with the aspect ratio

I've been struggling with this issue for some time now, trying to align the SVGs correctly for different width and height values. My viewBox has an aspect ratio of 16:9, and I want to scale the SVG accordingly. It's working fine for certain combi ...

What is the CSS method for altering the color of a slider's runnable track upon selection?

Seeking assistance in changing the slider track color upon selection. Struggling to achieve the desired outcome of altering the color as it slides. CSS: /* Custom Styles */ .text-size-slider { line-height: 100%; font-size: 14px; position: relative ...

Two rectangular divisions placed next to each other, with one perfectly centered and the height of the second division adjusting to match the height of the

I attempted to implement the Matthew James Taylor method, utilizing three columns. However, my main issue arises when I desire the middle column to dictate the height. In other words, if the center div is 500px in height, I want the right div's height ...

The behavior of Datatables varies depending on the screen resolution

In my data table, there are numerous entries with child tables on each row of the main table. I am currently in the process of incorporating this type of functionality into my table, with a few modifications to create a table within the child row. You can ...