The horizontal scroll feature is dysfunctional following the application of word-break in the table cell's td element

I am trying to create a bootstrap table with different widths for the td elements. I have multiple columns and want a horizontal scroll bar, but when I use word-break on any td, the scroll bar stops working.

Here is an example of what I have tried:

CSS

 <style>
  .check {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
  border: 1px solid #ddd;
  }
  </style>

HTML

<div style=" overflow-x: auto; background: red">
    <table class="check">
        <thead>
          <tr>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Points</th>
            <th>Points</th>
            <th>Points</th>
            <th>Points</th>
            <th>Points</th>
            <th>Points</th>
            <th>Points</th>
            <th>Points</th>
            <th>Points</th>
            <th>Points</th>
          </tr>
        </thead>
        <tbody>
            <tr>
              <td style=" max-width:100px">
              john
              </td>
              <td
              style="
              max-width: 10px;
              word-reak: breakAall
              "
              >
            Smith
            </td>
            <td>50</td>
            <td>50</td>
            <td>50</td>
            <td>50</td>
            <td>50</td>
            <td style="max-width:200px;word-break:break-all">
            12000050000600000070000080000</td>
            <td style=" max-width:100px">50</td>
            <td style=" max-width:100px">50</td>
            <td style=" max-width:100px">50</td>
            <td style=" max-width:100px">50</td>
        </tr>
    </tbody>
</table>
</div>

Answer №1

The reason for not seeing a scroll bar is that you do not have any other td elements in your table that would cause the width to exceed the screen size. A horizontal scroll bar only appears when the table width extends beyond the screen width. Additionally, you have specified that one of your td elements should break words instead of causing overflow. Most of your td elements also have a maximum width set, meaning they will only take up to 100px but can be less than that. As a result, none of these td elements will trigger a scroll bar to appear. Your data fits within the confines of the screen width.

As an illustration, the following code will display a scroll bar because there is no td with word-break styling, causing the entire row width to surpass the screen width.

<tr>
    <td style="max-width:100px">john</td>
    <td style="max-width:10px;word-reak:breakAall">Smith</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>50</td>
    <td>12000050000600000070000080000</td>
    <td style="max-width:200px;word-break:break-all">12000050000600000070000080000</td>
    <td style="max-width:100px">50</td>
    <td style="max-width:100px">50</td>
    <td style="max-width:100px">50</td>
    <td style="max-width:100px">50</td>
</tr>

View the example on this link: https://jsfiddle.net/7am5e46b/

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 is the quickest method to display the current year using Node.js?

Is there a way to efficiently print the current year in Node.js? I need to display the current year in the footer along with the Copyright notice. I know that using JavaScript works: <script type="text/javascript">document.write(new Date().getFullY ...

Tips for restricting the preloader display to once per session

My website features a preloader on every page. <div id="preloader" > <div id="status"></div> <div id="statustext">some text</div> </div> This preloader is activated using the following jQuery code: //<![CDATA[ var ...

The webpack server is having trouble loading the CSS stylesheet

Currently, I am working on creating a webpage using ReactJS. I encountered an issue where the css stylesheet I created to modify some bootstrap classes (specifically for my Navbar fonts) was not being applied when linked in the html file. To troubleshoot ...

Tapping on a DIV element that overlays a YouTube video on an iPad does not trigger any action

Currently, I am working on a webpage specifically designed for iPad and I have encountered an issue: I am trying to embed a YouTube video using an iframe and also need a div element to remain on top of it. To achieve this, I have added "?wmode=transparen ...

What is the best way to create a clickable anchor tag that is nested within a paragraph tag?

Here is the string I am working with: String txtLink = "<p>Apply directly in our <a href=\"https://theorem.applytojob.com/apply/TyJy6YCsOs/Experienced- Backend-Engineer-Ruby?source=GitHub+Jobs\">careers page</a></p>"; ...

An object that holds CSS attributes

I am working on a function that takes an element from the page and adds CSS styles to its attribute. The argument passed to this function should ideally be an object with keys like height, minWidth, flexDirection, and so on. function addStyle (el: HTMLElem ...

implement some level of control within the ngFor directive in Angular

For instance, let's say I have an ngfor loop: <ng-container *ngFor="let setting of settings | trackBy: trackById"> <button mat-button [matMenuTriggerFor]="menu">Menu</button> <mat-me ...

container div not fully extending to parent's height

I'm attempting to make the container div reach the full height of its parent element. The parent (body) is styled with the color info, while the container div is styled with the color primary. The intention is for the color of the container to stretch ...

Nuxt: Issue with Head function affecting title and meta tags

I need to customize the titles and meta descriptions of different pages on my Nuxt website. However, I am struggling to make it work using the head() method as indicated in the documentation. For example, in my contact.vue file: export default class Cont ...

Vanilla JS Rock, Paper, Scissors Game - Fails to reset classes upon restarting

Many questions have been raised about this particular topic, but a solution for vanilla js seems elusive. Let's delve into a new challenge: Rock paper scissors with vanilla js. The game functions properly on its own, but the issue arises when attemp ...

What strategies can be used to dynamically insert svg elements without compromising their interactivity?

Here's a thought-provoking question with no definitive answer: We have 3 different svg logos for phone, tablet, and desktop. Each has a hover effect, but there is one special logo that requires a unique hover effect and is wrapped in a link. I'd ...

Distinguishing background colors depending on the browser's compatibility with CSS properties

I've successfully designed a polka dot background using pure CSS: .polka-gr{ background-image: radial-gradient(#FAFFB3 20%, transparent 0), radial-gradient(#F1C3CB 20%, transparent 0); background-size: 30px 30px; background-positio ...

Even after setting a value to an HTML input field from the C# code behind, any modifications to the text are not being displayed

My form consists of input fields with the attributes type="text" and runat="server" to enable the code behind to access it. Users can input data and later edit the same data if selected from a list. However, after populating the form for editing and making ...

Moving the search bar on a WordPress mobile theme: A step-by-step guide

As a novice in web design, I've taken on the task of self-hosting a Wordpress site at noisehole.com using the MH Magazine template. One modification I made was to include a search bar above the header by creating a child theme and customizing it. How ...

How to Create a Hover Drop Down Menu that Disappears When Not Hovered Over

When I hover over the drop down menus on my Navbar, they display perfectly. However, it's impossible to click on the items in the menu because as soon as I move the cursor away from the main nav, it disappears. I've tried adding display:block and ...

Using jQuery to smoothly transition the page: first fade out the current content, then switch the background

I'm currently facing an issue with trying to create a step-by-step operation that involves fading the container div around a target div, changing the background, and then fading it back in. The problem is that all the functions in this block are being ...

Why does the hamburger menu appear below the div when I open it?

I had a vision to create a web app that would be fully functional on all devices, so I designed a navigation bar for full-screen display and a hamburger menu for smaller screens. However, I encountered a problem with my skills page. When I open the menu, i ...

Display or conceal a div based on the input value

Displaying div#cool should be triggered when the user enters the term "cool" into the input field. Similarly, showing div#good should be activated when the user types "good", and this functionality should operate seamlessly in real-time. ...

Having difficulty getting mask-image to function properly in Safari browser

My table row is styled with the following CSS code: .table-row-mask { mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0)); } <table><tr class="table-row-mask"><td>Test</td></tr></table> This ...

In NextJs SSR, external components from a different package do not inherit styles when applied

I have incorporated an external react component into my Next.js app code. Here is a snippet of how the component appears: <AppBar className={clsx(classes.header)}> </AppBar> export const header = makeStyles((theme) => ({ header: { ...