Strategies for managing lengthy words in HTML within a grid layout

I have utilized a div with display grid to create a column structure.

<div id="two-column-structure">
    <div></div>
    <div></div>
</div>

styled with css

div.two-column-structure {
    display: grid;
    grid-template-columns: 1fr 380px;
}

however, when I input a lengthy word in the first column like

asdjlkasjdlkjsalkdjalskjdlkajsdlakjsdlkajsdlkasjdlkasjdlasjdlkfahskldhfalksdjhflakjsdhflaksjdhflkasaklsjdhfaklsdhflaksdhflkajsdhlafkjdshflkajfsdhlfkajshdlkfajhsdlfjashdlkfjashdlkjahskldsfjhalskdjf

the layout overflows and my design becomes disordered.

I understand that who would do that but I think that might be the issue.

.two-column {
  display: grid;
  grid-template-columns: 1fr 380px;
  padding: 12px;
  border: 1px solid red;
  margin-bottom: 10px;
}

.two-column div {
  padding: 10px;
}

.two-column-i-tried {
  display: grid;
  grid-template-columns: 1fr 380px;
  padding: 12px;
  border: 1px solid green;
  margin-bottom: 10px;
}

.two-column-i-tried div:first-child {
  border: 1px solid blue;
  text-overflow: ellipse;
  overflow: hidden;
}
<div class="two-column">
  <div> slkdjflksdjfksajd;lkfaj;sldkjfa;lskdjflaksdkjghakljdfshgksldjfhgklsjdfhlgksjdfhgklsjdhflkgsjdhflkgsjhldfkjghskldjfhgskljdfhgksldhfgklsjdfhgklsjdhfgkjlshdfg
  </div>
  <div>
    Right Column
  </div>
</div>

<div class="two-column">
  <div> 
    Without long words it works fine but if there is no space in between it gets overflowed. What can I do for the same. I have used max-width, min-width, text-overflow and overflow which can be shown in two-column-i-tried class div
  </div>
  <div>
    Right Column
  </div>
</div>

<div class="two-column-i-tried">
  <div>  slkdjflksdjfksajd;lkfaj;sldkjfa;lskdjflaksdkjghakljdfshgksldjfhgklsjdfhlgksjdfhgklsjdhflkgsjdhflkgsjhldfkjghskldjfhgskljdfhgksldhfgklsjdfhgklsjdhfgkjlshdfg
  </div>
  <div>
    Right Column
  </div>
</div>


<div class="two-column-i-tried">
  <div> 
    Without long words it works fine but if there is no space in between it gets overflowed. What can I do for the same. I have used max-width, min-width, text-overflow and overflow which can be shown in two-column-i-tried class div
  </div>
  <div>
    Right Column
  </div>
</div>

In the html snippet when I use text-overflow and overflow to manage that lengthy text, it does not display ellipses as indicated in the code

Answer №1

Give this a shot:

.two-column div {
  padding: 10px;
  word-break: break-word; 
}

The word-break CSS property determines where line breaks should occur when text overflows its container.

For more details on this property, visit: https://developer.mozilla.org/en-US/docs/Web/CSS/word-break

Answer №2

Hey there, TheWorrier! Here's a suggestion for you to try out: utilize the CSS property text-overflow: "..."

.experimenting-with-two-columns div:first-child {
border: 2px dashed red;
overflow: hidden;
text-overflow: "ellipsis";
}

Answer №3

Give it a shot. grid-template-columns: repeat(3, 1fr); repeat(3, 1fr) generates 3 columns of the same width.

<style>
  .grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* Generates 3 columns of equal width */
    grid-gap: 20px; /* Sets the gap between grid items */
  }
  
  .grid-item {
    /* Define styles for the grid items */
  }
</style>

<div class="grid-container">
  <div class="grid-item">  Content goes here
</div>
  <div class="grid-item">   If there are no breaks in text, it overflows. How can this be prevented? Check the two-column-i-tried class div for solutions using max-width, min-width, text-overflow, and overflow properties.
</div>
  <div class="grid-item">Column 3</div>
</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

Is there a way to move my icon to the next row once it is added?

Can anyone suggest a style, bootstrap, or code solution for my issue? Currently, when I add an item, it is placed at the end of the row, but I want them to shift to the next row. Below are two images showing my current implementation: pic1 pic2 <div cl ...

Troubleshooting the onExited callback issue with Popover component in Material UI

<Popover key={element.name} classes={{ paper: classes.paper }} open={open} anchorEl={this.myRef.current} anchorOrigin={{ vertical: ' ...

Deactivate event handling for viewport widths below a specified threshold

Currently, I am attempting to deactivate a script when the width of the window falls below 700px. Despite reviewing suggestions from various sources, I have not been successful so far. window.onresize = function () { if(window.innerWidth < 700) { ...

Parent component in Material-ui theme distinguishing itself from child component of the same type

I'm working on customizing the styling of a Material UI Expansion Panel, specifically to apply my theme only to the main parent panel when it is expanded, and not to any nested panels within it. For instance: https://i.sstatic.net/nBhcN.png Here&ap ...

The PHP navigation is being obscured by the image gallery

I have implemented a PHP navigation system for my website using the code below: * { margin:0; padding:0; list-style:none; text-decoration:none; } img { position: absolute; top: 10px; left: 40%; } ul#navi { float:left; background:#31 ...

VPS in Laravel not functioning properly

I recently purchased a VPS and installed Laravel on it. The main page is working fine, displaying the subtitle "Laravel 5". However, when I tried to create a test page and added the route in the file: Route::get('/test', function() { return & ...

Adding a MySQL-PHP combination programmatically

Currently, I am working on a custom HTML page that sends data to PHP variables which are then utilized to generate customized SQL queries. function load_table($db, $old_table, $startRow, $nameColumn, $ipColumn, $addressColumn, $cityColumn, $stateColumn, $ ...

Positioning JQuery tooltips

I've been developing a simple tooltip tool (check out the fiddle link below), but I'm encountering some issues with positioning. My goal is to have the tooltip appear centered and above the clicked link, however right now it appears at the top le ...

Particles.js fails to persist as I scroll down the HTML page

After creating a website page, I incorporated Particles.js for the background. However, when I scroll down, the particles seem to be confined to the initial corner of the screen and do not continue downward. Here are my current particle settings: #particl ...

Which is better for website footers: tables or nested ULs?

I am trying to create a footer with a specific layout that consists of item titles and images. The design I have in mind includes three columns, where the middle one is larger than the sides. The middle column should be 550px wide, while the side columns s ...

Python - Syntax Error - Unable to Locate Element by XPath

Attempting to gather all elements of a webpage with the assistance of Selenium web driver and utilizing XPATH. Each row that needs to be gathered commences with the same text. Therefore, the following code was implemented: container = driver.find_elements ...

The markers on Google Maps are currently displaying in the wrong position, despite the latitude and longitude being correct

Utilizing the Google Maps API, I have implemented a system to dynamically add map markers tracking 2 of our company's vehicles. The website is developed in asp.net c# mvc with bootstrap 4.3.1. An ajax request retrieves the latest marker location from ...

How can you effectively enhance images for optimal web performance? (Transitioning from Figma wireframe to code)

As I work on building my portfolio from scratch, one challenge I am facing is how to include high-quality images without sacrificing site speed or image resolution. I used Figma to create wireframes, but when I exported the images, I noticed a significant ...

Creating a Background Image Using CSS3: A Step-by-Step Guide

Hey there! I'm trying to figure out how to recreate the image attached using CSS3. I've tried a few online tools for generating gradients, but no luck so far. :( I have the original image, but I really want to create the background using CSS3 in ...

Utilizing the bootstrap table-striped design to enhance the appearance of a table with empty cells

While utilizing Bootstrap for table displays, I've encountered an issue where the striped style is not being applied to rows with missing cells, resulting in an odd appearance. How can this be resolved? https://i.sstatic.net/1oKKO.png ...

Excess background spills beyond the width of the window

Looking to create a design similar to the following: A main container with 'n' child elements that may extend beyond the width of the window, causing the page to scroll horizontally instead of wrapping to the next line. This main container ...

Building a custom dialog box using Bootstrap 4 without using modals

I want to create a custom non-modal dialog box using Bootstrap 4. <div class="container"> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal"> Open dialog </button> <div class="modal fad ...

Encountering a broken image icon while attempting to the text alignment with an image in a React application

Working on a React app, I'm facing an issue aligning text with an image. Currently, it's showing a broken icon which makes me question if the path to the image is correct. Check out my file structure below.https://i.sstatic.net/zQ4Xd.png The ima ...

Updating the scope variable in an AngularJS directive

Recently delving into Angular, I encountered an issue: I have both a list view and a details view with tags. To facilitate navigating between the two views and loading new elements from a service upon click events, I created a directive. My aim is to also ...

Interacting with the Dropdown feature on the page causes the body of the page to shift

I am encountering an issue with 2 dropdowns in Datatables used to filter content. The problem arises when a dropdown is positioned on the right side of the page, causing a shift to the left by approximately 10px. Conversely, if the dropdown is placed on th ...