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

Passing an undefined value to the database via AJAX upon clicking a button

Hi there, I'm currently working on a table where I'm trying to perform an inline edit and update the value in the database by clicking on a button (an image). I've attempted to use an onclick function, but it seems to show "value=undefined&a ...

Adding list items to an unordered list without making them draggable using jQuery

How can I allow users to build a list of sports and drag them into a "cart" using jQuery? The issue I'm facing is that the appended list items are not draggable, and I'm unsure of how to solve this problem. /* JS code for sports.html */ $(fu ...

What is the best way to create a menu in JavaScript that includes a variable declaration?

Here is the menu I've created: <a id="page1" href="" onclick="var = page1">Home</a> <a id="page2" href="" >About us</a> <a id="page3" href="" >Services</a> <a id="page4" href="" >Partners</a> <a ...

What is the best way to maintain an ongoing sum of multiple values using bacon.js?

Experimenting with the power of bacon.js. I want to maintain a dynamic total of values from a set of text inputs. The example on the github page utilizes the .scan method along with an adding function, which functions well for simple increment and decremen ...

HTML: Dealing with issues in resizing and resolution with floating elements on the left and right using

Encountering some issues with the HTML code below when resizing the window: 1: The right bar suddenly drops down if the width is made too small. 2: The spacing between the content and the right bar expands as the window width increases. <style ty ...

What causes the Request.Params of IHttpHandler to be accurate on the initial call, but become null on the subsequent call?

My HTML/Javascript page utilizes a jQuery ajax call to communicate with a .NET ajax handler (.ASHX). The issue arises in subsequent calls where the parameters passed in the data object are unexpectedly NULL despite being correct during the first call. Her ...

What is the best way to link the width and height of a div with form fields?

I need to implement a feature where I can create multiple div elements that are draggable and resizable, and have their properties like width, height, etc. linked to corresponding objects in an array. For example, if I create six divs, there should be six ...

Tips for displaying an alert in the upcoming event loop

I recently started learning VueJS and decided to create a practice game to strengthen my understanding of the framework. http://jsfiddle.net/mzref4o0/1/ Within this game, the attack method is crucial in determining the winner: attack: function(isSpecial ...

"Enhancing user experience with React.js and Socket.io: dynamically updating list item positions based on

export default class ReactApp extends React.Component { constructor(props) { super(props) this.state = { status: [], services: [] } fetchData((err,opt, data) => { function Exists(l ...

What is the best way to consistently and frequently invoke a REST API in Angular 8 using RxJS?

I have developed a REST API that retrieves a list of values. My goal is to immediately invoke this API to fetch values and store them in a component's member variable. Subsequently, I plan to refresh the data every five minutes. Upon conducting some ...

What is the secret to keeping a hover effect active?

As I hover over the buttons in my stack, a text box appears on the right side. The intention is for this text box to act as a scroll box, but it disappears when I move my mouse to scroll because it needs to be continuously hovered upon to stay active. To ...

What will occur if I use an XMLHttpRequest to request a file that is currently being downloaded?

My goal is to enhance links in a progressive manner using the PJAX style. My plan was to layer this on top of some regular prefetch <link>s: <link rel="prefetch" href="next.html"/> If the browser has already downloaded next.html, then the PJA ...

Using Angular2 to assign the response from an http.get request to a class object

I am a beginner in Angular and I have a JSON file that holds the configuration URL for my application. Path: app/config/development.json { "apiUrl": "http://staging.domain.com:9000/", "debugging": true } Below is the content of my config.service.t ...

Struggling with Implementing Modals in Bootstrap 3.3.7

I've been encountering an issue with modal functionality. In order to troubleshoot my own modals, I decided to replicate the modal example code from Bootstrap's website into a new HTML file. Despite linking to the CDN, the modal does not functio ...

ajax is unable to decode a JSON string from a GET request

Currently, I am leveraging angularjs to retrieve userId, userTitle, and userComment from a form. These values are then sent to a PHP page from the controller for communication with a server. Everything works well when sending integers, but I face an issue ...

Establishing updated file path for resources in JavaScript based on environment

I'm currently facing an issue with my external Javascript file that uses the getScript() function to execute another JS file. Both files are located on static.mydomain.com, as I am trying to set up a Content Delivery Network (CDN) for the first time. ...

Ways to distinguish between two div elements that have scroll bars and those that do not

I created a div with CSS styling. .comment-list { margin: 20px 0; max-height: 100px; min-height: 100px; overflow-y: scroll; width: 100%; background-color:#000; } Here is the HTML code for the div: <div class="comment-list"> </div> When the ...

Check to see if modifying the HTML using jQuery results in any errors

Although it may sound straightforward, let me clarify. I am utilizing ajax calls to update the content of the body and I aim to trigger an alert if the updating process fails on the client side, specifically after receiving a response from ajax in case of ...

What is the best way to integrate PHP code within CSS?

I'm working on a script that requires me to add PHP code within a CSS stylesheet. However, when I attempt to do so, nothing seems to happen! Is it even possible to include PHP code in a CSS file? ...

The CSS transition feature does not seem to be functioning properly when it comes to displaying

In my Next.js application, I am using a card component with a "read more" link that should expand the card when clicked. To achieve this behavior, I integrated the "react-show-more" library from https://github.com/One-com/react-show-more. I tried to add ...