Tips for keeping text within a div and preventing it from breaking outside

This is an example of the HTML card structure:

<li class="col-md-4">
  <div class="categorylist-item">
    <a class="cid-201728169" href="xxxxxxxx">
      <h4>Backoffice</h4>
      <div class="linebreak"></div>
      <p class="description">Orders, deliveries, inventory, promotions, accounting, etc.</p> 
      <!--<p class="readmore">Read more</p>-->
    </a>
  </div>
</li>
.container.home .categorylist-item h4 {
  font-size: 25px;
    font-weight: bold;
  margin-bottom: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.container.home .categorylist-item .description {
  display: none;
  font-size: 18px;
  font-weight:400;
  margin-top:15px;
}

.container.home .categorylist-item:hover .description {
  display: block;
}

.container.home .categorylist-item .readmore {
  font-size: 16px;
    font-weight: 500;
  color: #212529;
  display:none;
}

.container.home .categorylist-item:hover .readmore {
  display:block;
}

.container.home .categorylist-item .readmore:after {
  content: " \00bb";
}

/*Columns on startpage transitions*/

.categorylist-item .cid-201728169 { /*First column transition*/
    -moz-transform: translateY(100%);
    -webkit-transform: translateY(100%);
    -ms-transform: translateY(100%);
    transform: translateY(100%);
  transition: .5s;
}

.categorylist-item:hover .cid-201728169,/*First column transition*/
.categorylist-item .cid-201728169 {
    -moz-transform: translateY(0);
    -webkit-transform: translateY(0);
    -ms-transform: translateY(0);
    transform: translateY(0);
}

Please do not attempt to run this code...

Here is a simple visualization:

When the card is not hovered over:

https://i.sstatic.net/HWDjB.png

When you hover over the card:

https://i.sstatic.net/KXNNY.png

The issue faced is:

https://i.sstatic.net/bgXmz.png

The p tag (description) extends beyond the box.

Is there a way to prevent the text from breaking outside the div..?

Any suggestions?

Answer №1

If you're wondering how to keep text from breaking outside of a div, one solution is to add the CSS property overflow: hidden to the container holding the text. This will ensure that any text exceeding the boundaries of the container will be hidden from view. While this can prevent unsightly text spills, it may not always be the most user-friendly option as users may not realize they need to scroll to see the full content.

A better approach would be to adjust the size, margin, or padding of the elements within the div to allow for more space and accommodate the full description without it overflowing.

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

Rendering dynamic HTML content using EJS

I've created a blog application using Express and MongoDB, with EJS for rendering the data. My issue lies in the styling of the content to resemble a paragraph: <div class="show-post__content"> <%= post.body %> </div> The po ...

Trouble encountered when utilizing jQuery for XML to HTML conversion and vice versa (CDATA mistakenly transformed into HTML comments)

I am in the process of developing a plugin/bookmarklet that is designed to extract an XML document from the <textarea> element on a web page, make modifications to the XML content, and then reinsert the updated version back into the <textarea> ...

Change the position of the background image when hovering over the div element

Looking for advice on how to create a div with a background image that only appears when hovered over. I also want the image to either zoom in or move to the sides while hovering. Here is my current progress. .seg1 p:first-child { font-size: 20px; p ...

Creating a responsive button group with four Bootstrap 4 buttons arranged in two rows

How can I create a responsive one button group in bootstrap 4 with four buttons, arranged in two rows? ...

Creating a portion of a Bootstrap Dropdown menu that is scrollable

Looking for a way to design a friends requests menu using Bootstrap's dropdown feature. My goal is to create a scrollable menu where friend requests overflow if there are more than 3, while keeping the "you have 2 requests" and "check all requests" op ...

Functionalities of HTML controls

I currently have a select element in my HTML code which looks like this: <select> <option id="US" value="US"> </option> <option id="Canada" value="Canada"> </option> </select> My requirements are twofold: ...

What is the most efficient method to convert a CSS transform attribute into a top attribute?

Using a Javascript plugin named Skrollr, I am incorporating the functionality to shift the position of elements on my webpage as the user scrolls. However, a challenge has arisen as I notice that adjusting the top position causes noticeable jitteriness in ...

An error occurred due to a state update being attempted on an unmounted component. The solution is to properly cancel all subscriptions and asynchronous tasks in a

Currently, I am attempting to utilize ListEmptyComponent within a FlatList. If there is no data present, I intend to display ListEmptyComponent={} However, in the Loadingsecond component, I am using useEffect to render when loading is true; if there is s ...

What is the most effective method for sorting through vast amounts of data with Javascript, React, and Redux?

Currently, I am working with a minimum JSON data set of 90k [...] and utilizing the .filter method. Everything is functioning correctly without any issues, however, from a performance standpoint, I am curious about potential improvements. Any suggestions o ...

Guide on how to reset a counter to 0 using a JavaScript button

I currently have a JavaScript counter and a button that increments the counter by 1. Here is my existing code: var counter = 0; var a = 0; var add = function(valueToAdd){ a += valueToAdd; document.getElementById('Value&ap ...

What's the reason behind the data not being retrieved by $.ajax?

After attempting to validate a form and send the values using $.ajax, I encountered an error message stating "Undefined index: is_ajax". Why is the form_data not being received? What could be causing this issue and how can it be resolved? function validat ...

Using AJAX with the GET method, send a form submission to retrieve a response using XMLHTTPRequest

I am working on a form where users can select values from two dropdown menus. The options in the dropdowns are populated dynamically from a JavaScript file, which contains a list of exchange rates. I have written the code to calculate and display the resul ...

What are the steps to fix the CORS problem when sending AJAX requests from a frontend to a Flask server?

My current project involves creating a web application with Flask for the backend and JavaScript for the frontend. However, I'm encountering challenges with CORS policy when attempting to send AJAX requests from my frontend to the Flask server. Below ...

Submitting data with a checkbox and dropdown menu

Currently, I am working with a HTML table where rows are generated dynamically inside a for loop. Each row consists of a checkbox with a unique value but the same name ("checkboxes"), and at the end of each row there is a select element also with the same ...

How to iterate through a JavaScript array in reverse order using a for loop and the array's length property

When looking to iterate through an array with the values [8,7,6,5,4], some may wonder why a for loop using the length of 5 continues to function even though there is no element at index 5 in the array. for(let i=array.length;i>=0;i++){ //do somethin ...

Can a shared state management system be effectively implemented in CLI applications without relying on an external database?

I am looking to develop a CLI application, and while this question may not be tied to a specific technology, I have chosen to use Node with command-line-commands for demonstration purposes (although there are other options like commander). Below is a snip ...

Tips for setting the value of the 'ng-style' directive depending on the number of times 'ng-repeat' is repeated

I am working on an AngularJS project with a sample snippet that uses the ng-repeat directive to display names in a table. I want to add the ng-style directive to include a vertical scroll bar in the table based on the number of rows. How can I modify the c ...

Changing the size of an input field in Bootstrap 4 by utilizing the input-group-append class

Currently, I am working on setting up a pay rate feature that includes two input boxes for numbers. However, I am facing an issue where the input boxes are stretching too much, causing the cents field to drop down to the next line. The Maxlength property ...

(Vue with Typescript) Error: Component cannot be mounted as template or render function is not defined

Having trouble mounting component due to template or render function not defined. Hello everyone, I'm currently attempting to incorporate Typescript into my Laravel / Vue project. However, I've been encountering issues such as the following erro ...

Ensuring the validation of JSON schemas with dynamically generated keys using Typescript

I have a directory called 'schemas' that holds various JSON files containing different schemas. For instance, /schemas/banana-schema.json { "$schema": "http://json-schema.org/draft-06/schema", "type": "object", "properties": { "banan ...