When using the `display: table-cell` property on a div element, it does not automatically respect

How can I restrict the width of columns by defining a width attribute on the div.dcolumn DOM element to preserve the layout with overflowing cells? I want the content of any overflowing cell (like the 9px column) to be hidden while maintaining the specified width values. What are my options?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html style='height:100%'>
       <head>
          <style>
            .header {
              background-color: #eeeeee;
              padding: 0 0 0 0;
              border: 1px solid #cccccc;
              cursor: default;
              -webkit-touch-callout: none;
              -webkit-user-select: none;
              -khtml-user-select: none;
              -moz-user-select: none;
              -ms-user-select: none;
              -o-user-select: none;
              user-select: none;
              overflow: hidden;
            }
    
            .dtable {
              display: table;
              position: relative;
              table-layout: fixed;
            }
            .drow {
              display: table-row;
            }
            .dcell {
              display: table-cell;
              overflow: hidden;
              padding: 0 0 0 0;
              border: 1px solid #cccccc;
              cursor: default;
            }
            .dcolumn {
              display: table-column;
            }
          </style>
       </head>
       <body>
          <div class="dtable" style="top: 0px; left: 0px; height: 125px;">
             <div class="dcolumn" style="width: 39px;"></div>
             <div class="dcolumn" style="width: 19px;"></div>
             <div class="dcolumn" style="width: 9px;"></div>
             <div class="dcolumn" style="width: 39px;"></div>
             <div class="dcolumn" style="width: 19px;"></div>
             <div class="drow header" style="height: 25px;">
                <div class="dcell">0</div>
                <div class="dcell">1</div>
                <div class="dcell">2</div>
                <div class="dcell">3</div>
                <div class="dcell">4</div>
             </div>
             <div class="drow" style="height: 25px;">
                <div class="dcell">0:0</div>
                <div class="dcell">0:1</div>
                <div class="dcell">long line not truncated</div>
                <div class="dcell">0:3</div>
                <div class="dcell">0:4</div>
             </div>
             <div class="drow" style="height: 25px;">
                <div class="dcell">1:0</div>
                <div class="dcell">1:1</div>
                <div class="dcell">1:2</div>
                <div class="dcell">1:3</div>
                <div class="dcell">1:4</div>
             </div>
          </div>
       </body>
    </html>

Answer №1

For achieving the ellipsis effect, a <span> has been nested inside of the .dcell element since the effect does not directly apply to the .dcell. Additionally, a width of 25px has been set for the .dcell.

This implementation should meet your requirements.

.header {
  background-color: #eeeeee;
  padding: 0 0 0 0;
  border: 1px solid #cccccc;
  cursor: default;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -o-user-select: none;
  user-select: none;
  overflow: hidden;
}

.dtable {
  display: table;
  position: relative;
  table-layout: fixed;
}

.drow {
  display: table-row;
}

.dcell {
  display: table-cell;
  overflow: hidden;
  width: 25px;
  padding: 0 0 0 0;
  border: 1px solid #cccccc;
  cursor: default;
}

.dcolumn {
  display: table-column;
}

.cell-data {
  display:block;
  width:inherit;
  overflow: hidden;
  white-space: nowrap; 
  text-overflow: ellipsis;
}
<div class="dtable" style="top: 0px; left: 0px; height: 125px;">
  <div class="dcolumn" style="width: 39px;"></div>
  <div class="dcolumn" style="width: 19px;"></div>
  <div class="dcolumn" style="width: 9px;"></div>
  <div class="dcolumn" style="width: 39px;"></div>
  <div class="dcolumn" style="width: 19px;"></div>
  <div class="drow header" style="height: 25px;">
    <div class="dcell">0</div>
    <div class="dcell">1</div>
    <div class="dcell">2</div>
    <div class="dcell">3</div>
    <div class="dcell">4</div>
  </div>
  <div class="drow" style="height: 25px;">
    <div class="dcell">0:0</div>
    <div class="dcell">0:1</div>
    <div class="dcell">
      <span class="cell-data">long line not truncated</span></div>
    <div class="dcell">0:3</div>
    <div class="dcell">0:4</div>
  </div>
  <div class="drow" style="height: 25px;">
    <div class="dcell">1:0</div>
    <div class="dcell">1:1</div>
    <div class="dcell">1:2</div>
    <div class="dcell">1:3</div>
    <div class="dcell">1:4</div>
  </div>
</div>

Answer №2

After much consideration, I have discovered the solution: The key is to establish the total width of the table as the cumulative sum of all columns (and avoid wrapping with white-space: nowrap).

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html style='height:100%'>
       <head>
          <style>
            .header {
              background-color: #eeeeee;
              padding: 0 0 0 0;
              border: 1px solid #cccccc;
              cursor: default;
              -webkit-touch-callout: none;
              -webkit-user-select: none;
              -khtml-user-select: none;
              -moz-user-select: none;
              -ms-user-select: none;
              -o-user-select: none;
              user-select: none;
              overflow: hidden;
            }
    
            .dtable {
              display: table;
              position: relative;
              table-layout: fixed;
            }
            .drow {
              display: table-row;
            }
            .dcell {
              display: table-cell;
              overflow: hidden;
              padding: 0 0 0 0;
              border: 1px solid #cccccc;
              cursor: default;
              white-space: nowrap;
            }
            .dcolumn {
              display: table-column;
            }
          </style>
       </head>
       <body>
          <div class="dtable" style="top: 0px; left: 0px; height: 125px; width: 130px">
             <div class="dcolumn" style="width: 39px;"></div>
             <div class="dcolumn" style="width: 19px;"></div>
             <div class="dcolumn" style="width: 9px;"></div>
             <div class="dcolumn" style="width: 39px;"></div>
             <div class="dcolumn" style="width: 19px;"></div>
             <div class="drow header" style="height: 25px;">
                <div class="dcell">0</div>
                <div class="dcell">1</div>
                <div class="dcell">2</div>
                <div class="dcell">3</div>
                <div class="dcell">4</div>
             </div>
             <div class="drow" style="height: 25px;">
                <div class="dcell">0:0</div>
                <div class="dcell">0:1</div>
                <div class="dcell">long line not truncated</div>
                <div class="dcell">0:3</div>
                <div class="dcell">0:4</div>
             </div>
             <div class="drow" style="height: 25px;">
                <div class="dcell">1:0</div>
                <div class="dcell">1:1</div>
                <div class="dcell">1:2</div>
                <div class="dcell">1:3</div>
                <div class="dcell">1:4</div>
             </div>
          </div>
       </body>
    </html>

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

The functionality of jQuery clone is failing when draggable items are used to generate a duplicated version

I'm new to implementing jQuery Draggable functionality and I'm trying to create a drag and drop feature where the drag element is cloned and dropped to a specific location. Here is the code I have so far: $(function () { $('#D ...

Invoking a PHP function file through Ajax

Currently, I am utilizing Ajax with Bootstrap Modal to retrieve content from a Database. One of the functions in my functions file is responsible for verifying the existence of a remote file: function checkRemoteFile($url) { $ch = curl_init(); cur ...

Trouble with CSS Class Showing Up Only When Hovered

My goal is to make the .panel-text element visible only when a user hovers over the panel. I attempted to use the overlay CSS class, but I encountered issues where the text either wouldn't show at all or would always be displayed. Here is what I have ...

Utilizing JQuery to alter the text color if validation fails when entering a value

Is there a way to change the text in the input box to red when PHP validation fails using JQuery? I had success with Javascript, but it kept disappearing every time I clicked submit... <form class="link-form" method="post" action=""> <la ...

Ways to extract the id after clicking

In my code, I have a query called snapshot.forEach that functions similarly to a for loop in looping through all of my Firebase data and displaying it with a div tag containing a click event. When another user clicks on this div tag, the event will retriev ...

Verifying picture quality prior to transferring to a remote server

I am facing an issue with my image upload function to a remote server. The upload function works fine on its own, but when I integrate it into the size validation block, it stops working properly. <p> <input type="file" id="BtnBro ...

"Encountered a problem while setting up the Mailgun webhook to handle both multipart and URL encoded

I have been working on creating a web hook listener for Mailgun, and I encountered an issue when I realized that Mailgun can post webhooks using either multipart or x-www-form-urlencoded content-types. Currently, my code uses Multer to handle multipart b ...

Design elements using CSS within the <th> tags

When working with HTML tables, the use of a <th> element allows for the implementation of a scope attribute. This attribute serves to indicate whether the header cell is associated with its subsequent column, row, or group. Is it feasible to leverage ...

What is the solution to the error message "Cannot assign to read only property 'exports' of object '#<Object>' when attempting to add an additional function to module.exports?"

I've been struggling for the past 5 days with this issue. Despite numerous Google searches, I haven't found a solution that works for me. I have a file called utils.js which contains useful functions to assist me. However, when I include the func ...

recurring issues with time outs when making ajax requests

During the development of my website, I tested it as localhost. Now that it's nearly complete, I switched to using my local IP address and noticed that about 30% of my ajax calls result in time out errors or 'failed to load resource errors'. ...

At what point should I expect a promise in Protractor to be resolved?

Despite there being similar inquiries on this topic, I am struggling to comprehend them. Allow me to illustrate with an example, where my task is to click a button and verify the URL. Initially, I thought it should be coded as: element(by.id('butto ...

Spring Boot fails to recognize path variable data sent from Angular

When working with Angular 7, I encountered a situation where I needed to pass a value from the service class of Angular. Here is how I achieved it: executeHelloWorldBeanServiceWithPathVariable(name){ console.log("name coming from here"+name); retu ...

Switch Button Hyperlink in HTML/CSS

I have the following code: document.addEventListener("DOMContentLoaded", function(event) { (function() { requestAnimationFrame(function() { var banner; banner = document.querySelector('.exponea-banner3'); banner.classList ...

What is the easiest way to locate the ID of an iframe embedded within a webpage?

Currently, I am focused on developing small JavaScript/HTML5 ads for a webpage. Each advertisement comes with its own iframe that occupies a specific size and space on the page. In order to accommodate an expandable ad that needs to surpass the predetermin ...

Can you explain the process of implementing @media queries in SASS?

I am having some trouble understanding the syntax for media queries in SASS. I attempted to use this particular line of code, but it resulted in an error: @media screen (max-width: 1550px) #server-name left: 80% ...

Tips on saving a form submit button data to localStorage

As a newcomer, I am on a quest to make this function properly. My goal is to create a form where the submit button saves data to the localStorage. Here's what I have tried thus far. <script> function storeRecipe() { localStorage.setItem($(" ...

The inline script is deemed non-compliant as it infringes upon the Content Security Policy directive: "script-src 'self'"

My chrome-extension is built using react-create-app. However, I encountered an error when running npm run build in react-create-app: Refused to execute inline script because it violates the following Content Security Policy directive: "script-src &apo ...

Is there a way to access and troubleshoot the complete source code within .vue files?

I've been struggling for hours trying to understand why I'm unable to view the full source of my .vue files in the Chrome debugger. When I click on webpack://, I can see the files listed there like they are in my project tree, but when I try to o ...

Accordion feature exclusively toggles the initial item

I am having an issue with the code in my index.php file. Only the first item in the accordion menu is showing up correctly. When I click on "Status" or "Repeated", I expect to see the sub-menu of the clicked item, but instead, I am getting the result from ...

Is there a reason why async functions do not function properly within a controller's get() handler?

Utilizing Node and Express along with the mssql npm package, I establish a connection to an SQL Server database in my app.js file by setting up a global variable that creates a connectionPool (I've excluded some boilerplate code for brevity): const m ...