Bootstrap table with set width and text wrapping in td elements

I'm currently working with Bootstrap CSS to create a fixed-length table where the contents inside each cell (td) can wrap into multiple lines if necessary.

Below is a snippet of my code that's not functioning as intended. The content within the td cells is not wrapping inside cells of the specified fixed length.

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    
    <div class="container">
      <h2>Basic Table</h2>
      <p>The .table class adds basic styling (light padding and only horizontal dividers) to a table:</p>  
      <div class="table-responsive">
      <table class="table fixed">
        <thead>
          <tr>
            <th class="col-xs-3">Firstname</th>
            <th class="col-xs-3">Lastname</th>
            <th class="col-xs-3">Email</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td class="col-xs-3">Johdddddddddddd...</td>
            <td class="col-xs-3">Doe</td>
            <td class="col-xs-3"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4bebbbcba94b1acb5b9a4...">[email protected]</a></td>
          </tr>
          <tr>
            <td class="col-xs-3">Mary</td>
            <td class="col-xs-3">Moe</td>
            <td class="col-xs-3"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bad7dbc8c3fadfc2dbd7...">[email protected]</a></td>
          </tr>
          <tr>
            <td class="col-xs-3">July</td>
            <td class="col-xs-3">Dooley</td>
            <td ><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f49e81988db4918c9599849891d...">[email protected]</a></td>
          </tr>
        </tbody>
      </table>
      </div>
    </div>

The output, shown in the image linkedhttps://i.sstatic.net/comGP.png, displays the overflowing content within the cell.

Answer №2

The issue arises when inputting excessively long strings like 'sssssssssssssssssssssssss' as the system misconstrues it as a single word. This problem persists even with responsive layouts that fail to break words intelligently. To address this, you can utilize the code snippet below.

td{
    word-break: break-all;
}

Answer №3

Implement the word wrap CSS property within the td element

  overflow-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

Tips for resizing a 100% div without displaying vertical scrollbars in the browser

I am facing an issue with a table that has three rows. I have a main #container div with a height of 100%, and inside it is a table with 3 rows. The first and last row contain fixed size content. However, in the second row, there is a #content div with a h ...

Is it normal for e.target.result to only work after two or three tries?

Attempting to resize an image on the client side before sending it to the server has been challenging for me. Sometimes, the image does not align correctly with the canvas used for resizing. I have noticed that I need to send the resized image at least tw ...

Recursive instruction malfunctioning

I'm currently trying to develop a custom recursion directive, but unfortunately it's not functioning as expected. I have followed the instructions outlined here: Recursion in Angular directives For reference, you can view the fiddle here: http ...

Ways to delete a property from an element that was originally included with jquery

On my jsp page, I am implementing a jQuery autocomplete feature for a text field with the id "mytextfield". jQuery(function(){ $("#mytextfield").autocomplete("popuppages/listall.jsp"); }); Sometimes, based on user input and pr ...

stopping a float-left div from being pushed down by a table

I am facing an issue with two float:left divs that are supposed to stack left-to-right. One div is a fixed width left nav, while the other should span the remaining width of the browser. The problem arises when there is a table in the second div with multi ...

Text that fades in and out based on scrolling past a specific point

There's a text containing <p> and <h1>. The text finishes with one <h1>. I'm looking to speed up the Y translation of the <p> twice when I reach the bottom of the document (where the last h1 is located in the middle of th ...

What are the differences between incorporating JavaScript directly into HTML and writing it in a separate file?

I need help converting this JavaScript embedded in HTML code into a standalone JavaScript file. I am creating a toggle switch that, when clicked, should go to a new page after the transformation. I am looking for the non-embedded version of the function. H ...

Achieving uniform height for child images within adaptable Bootstrap 4 columns. What's the secret?

I am looking to create 3 columns using Bootstrap 4 that will adjust their width dynamically while keeping the padding consistent. I also want to ensure that the height of each image in all three columns remains the same regardless of changes in page width. ...

The uninterrupted execution of a server-side script is occurring without the need for

Greetings! I am currently working on a web project that combines HTML5 and Java with the Hibernate framework, utilizing AJAX as a bridge between them. My approach involves developing servlets that are connected to HTML5 forms and use AJAX to send data. Ho ...

Toggle Visibility of Div Based on Matching Class Name When Clicked

Just delving into the world of jQuery and could use some guidance. Is there a way to show a div with a matching class when a specific button is clicked? For example, clicking on a button with the class '.project1' should display the corresponding ...

An unusual icon with three varying sizes in a single file

I have come across an interesting favicon file. Click here to download the favicon file Unfortunately, I am unable to upload this image file as it does not meet the required format standards. Upon viewing the file in Windows 7, a fascinating discovery w ...

Reset the text input field when the dropdown menu is set to 'no/other'

CURRENT: Choosing from a dropdown menu with options 'Yes' or 'No'. If 'Yes' is chosen: Display additional dropdowns/inputs for entry If 'No' is chosen: Conceal additional dropdowns/inputs WANT: I am looking to imp ...

Background image not displaying

My web page has a background image set using this CSS: body, html { background-image: url(Content/Images/bg-lounge-2-l.jpg); background-repeat: repeat; background-attachment: fixed; /*background-position: 0 -390px;*/ } ...

What are the steps to create a responsive form using CSS?

I have a screenshot below that needs to be recreated using HTML/CSS. This design should be consistent in both desktop and mobile views. https://i.stack.imgur.com/cnfHt.png Currently, I have managed to replicate this in a JSFiddle which looks good on desk ...

What could be the reason for the minimum width exceeding the maximum width?

As I delve into the world of web design, I am facing a bit of a learning curve after such a long break from building sites from scratch. One thing that caught my attention in Dreamweaver is the pre-fabricated Bootstrap code within the .css files. I' ...

Looping through a nested for loop within an HTML table

I am currently working on generating a dynamic table using Lists of varying sizes. My first list is a List of Cars List<Car>. I have successfully placed the names of different car companies in the header. Next, I have a List<List<CarSales>& ...

The backend error message isn't triggering an alert!

My current issue involves using jQuery to execute a .php file. Whenever an error occurs in the backend, I want to display an alert message with the error details. However, when intentionally submitting with an error, no alert pops up and it just proceeds t ...

The h3 element is not responding to the adjacent sibling selector

Below is my HTML DOM structure. I am trying to remove the margin and padding for all h3 elements that are immediate siblings of a div with the id "successor". I attempted to achieve this using the adjacent sibling selector "+", but unfortunately, I'm ...

Using regular expressions in Python with PyQt4 to eliminate anchor tags from HTML links in text

When using my QTextBrowser, I am able to identify links such as "www.test.com" with the following regular expression: re.compile( r"(\b(?:(?:https?|ftp|file)://|www\.|ftp\.)[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|])" ...

I am experiencing issues with my three.js script not functioning properly within the context of a

I have been working on implementing a raycaster function in my project that only activates when an entity is visible. To achieve this, I was advised to create a custom script for better control. I have set up all entities and their child entities to be in ...