Stop editable content div from expanding horizontally

I have a contenteditable div element with the class ".textarea_mask."

<div class=".textarea_mask" contenteditable ></div>

My goal is to make this div act like a text area. It functions correctly in modern browsers, but I am having issues with Internet Explorer 8. When entering a long phrase like

abcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuvqxyzabcdefghijklmnopqrstuvqxyz
, the text breaches the boundaries of the div and causes it to expand or hide when applying overflow-x: none.

Is there a way using jQuery to detect overflow and truncate the long phrase so it fits within the div's width?

Note: Typing standard text like "A cat and a dog" will automatically move to the next line.

Thank you for any assistance.

Answer №1

If you're looking to implement text wrapping in CSS, the property you're searching for is overflow-wrap. Most browsers still support it as 'word-wrap' (http://caniuse.com/wordwrap).

You can learn more about it on MDN: https://developer.mozilla.org/en-US/docs/CSS/word-wrap

To see a demonstration, check out this link: http://jsfiddle.net/THC5q/4/

Here's an example of how you could use it in your HTML:

<div>
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
</div>​

And here's the corresponding CSS:

div {
    width: 200px;
    background-color: #ff0;
    word-wrap: break-word;
}

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

Creating CSS boxes in a dual column layout with a step-by-step approach

Currently, I am in the process of developing a user interface for a menu that looks something like this: https://i.sstatic.net/GuzRm.png I am exploring different implementation methods for this design. In this project, I am utilizing Bootstrap framework. ...

Optimize Google Places Autocomplete: Customize the way search results are shown after selection (display only street name and number)

Struggling to update Google's autocomplete input value to only show the selected "streetname number" instead of the full address. It works when the user hits enter, but the value changes back when the input field loses focus. Looking for a simple sol ...

Understanding how to retrieve a particular list item in JQuery without having the index in advance

I have a lengthy list that is broken down into various subheadings. How can I retrieve the second to last element of the list before a specific subheading, provided it is not the final element? Is it possible to do this if I know the ID of the subheading? ...

Firebase hosting adjusts the transparency of an element to 1% whenever it detects the presence of CSS opacity

I'm currently working on a website using Vue.js and Firebase. Everything runs smoothly locally, including a button with a desired low opacity. However, when I deploy the site to Firebase Hosting, the button's opacity inexplicably changes to 1% an ...

Build a basic website featuring a left-side menu and content on the right side

I intend to design a straightforward website featuring: A left menu with clickable items Clicking on each item will change the right menu to display new content consisting of a title, picture 1, text description, and picture 2. This format will be consis ...

Why is my node.js react app failing to detect the index.html file?

Take a look at the app here: git repository The issue I'm facing is that index.html doesn't seem to be properly linked, resulting in: 1) The website not being responsive for mobile devices 2) Lack of a favicon https://i.sstatic.net/l4hHJ.png ...

Tips for managing JSON.stringify information within Laravel

Trying to retrieve data from Ajax in Laravel controller for storage, but encountering an error as shown in the image below. Need help identifying the mistake. Laravel Controller@ajaxstore public function ajaxstore(Request $request) { //Event::create ...

Adjust the width of the element to match the size of the image within

My webpage features an image along with some accompanying metadata that I want to be centered on the page. I want the div holding the metadata to be the same width as the image. Here's an example: Unfortunately, I am unable to determine the image&apo ...

Prioritize the Menu display

Is there a way to bring the menu's black background in front of the body text in the image below? Here is the JSFiddle link for reference: https://jsfiddle.net/johnking/j58cubux/6/ The issue occurs when scrolling down and the menu is not clearly vi ...

Refreshing the identification of a button

I have been working on updating an ID with a value from another button. Here is my current progress: $('.viewemployment').on('click', function(e){ var url = '<?php echo Config::get('URL'); ?>dashboard/employmen ...

Creating a scrolling background effect using HTML and CSS: ``Background Parallax

I'm trying to keep the background of my HTML document fixed in the upper left corner, so that when a user scrolls through the page, they only see parts of it. Here's the code I'm using: <body style="background-image: url(background.png) ...

Creating dynamic content in the Ajax-enabled Smart Admin theme: A step-by-step guide

As I work on developing an application for a client, my focus is on creating a web service using Laravel5 for the backend. To enhance the user interface of this web service, I have chosen to incorporate the Smart Admin Theme, specifically utilizing the Aja ...

How can you modify the color of a card in React by mapping through an array and evaluating its value?

I'm attempting to modify the color of a card depending on the current slot value, which is an object in an array. While I am iterating through each card, I want to adjust the background color of the card based on this value. However, my current method ...

jQuery AJAX request unexpectedly terminates

I am encountering an issue with my ajax calls to a php script that should process the data and display results. Unfortunately, the calls are timing out in both Chrome and Firefox, and appear in red when I inspect them. This is my current ajax code: $.aj ...

Toggle the visibility of items based on the user's login status

Below is the code snippet for when the user is logged out: <div class="fusion-secondary-main-menu"> <div class="fusion-row"> <?php avada_main_menu(); ?> <?php avada_mobile_menu_search( ...

Only the main page is accessible quickly through Express

Currently, I am delving into learning Express and leveraging FS to load my HTML Page. My research on this topic only led me to references of using ASP.NET instead of Express. Here is a snippet from my Server.js file: var express = require('express&a ...

OpenLayers 4 - adjusting the view to the boundaries of chosen features

Hey everyone, I ran into an issue yesterday with zooming to selected features and I'm hoping someone can point me in the right direction. Here's the situation... I'm working on implementing an autocomplete/search bar using the Materialize M ...

Launch the desired div in a fancybox from a separate webpage

i have a table with links to another html doc like this <div id="gallery_box"> <ul> <li> <a href="http://www.geestkracht.com" target="_blank"><img src="images/gallery/Geestkracht.jpg" alt="G ...

What is the best way to customize the icon-bar in react-bootstrap's Navbar?

I am trying to customize the icon-bar in a react-bootstrap's Navbar component by setting its background color to white. However, my webpack scss loader is preventing me from styling CSS classes with dashes, as it only allows camel case. This restricti ...

Changing or toggling the visibility of links once the week is finished

I have a total of 4 links available, but I want to display only one link at a time, highlighting a different lunch option every week. Once all 4 weeks have passed, the first lunch menu will be shown again, starting from Monday. <div class="wrapper& ...