Prevent one individual cell in a table from dictating the overall table width

A    B
A    B
A    X
A    B

In a contained block with a fixed width of 400px, there is a table. When the browser width drops below 421px, the width of the containing block changes to 95%. The cells labeled "A" and "B" contain simple text. There is one cell containing a link that has white-space:nowrap applied.

The goal is for the table to determine its dimensions automatically (without using table-layout:fixed-width) but not include cell "X" in determining the width of the second column. It's acceptable to hide any content in cell "X" that doesn't fit.

Various attempts have been made to apply width:100% with overflow:hidden on different elements without success.

HTML

<table>
   <tr>
       <th style="vertical-align:bottom;">
           <figure>
               <div class="minical-mo">month</div>
               <div class="minical-da">date</div>
           </figure>
       </th>
       <td style="vertical-align:bottom;"><h2>summary</h2></td>
   </tr>
   <tr>
       <th class="space">Calendar</th>
       <td class="space"></td>
   </tr>
   <tr>
       <th class="space">Date</th>
       <td class="space">date</td>
   </tr>
   <tr>
       <th>Start Time</th>
       <td>time</td>
   </tr>
   <tr>
       <th>End Time</th>
       <td>time</td>
   </tr>
   <tr>
       <th>Location</th>
       <td>location</td>
   </tr>
   <tr>
       <th class="space">Attachment</th>
       <td class="space link"><a href="link">link</a></td>
   </tr>
   <tr>
       <th class="space">Description</th>
       <td class="space">long desc</td>
   </tr>
</table>

SCSS

table{  
   width:100%;
   margin:1em 0;
   th{
       color:$c_modal;
       text-align:right;
       font-size:.85em;
       padding: 3px;
       vertical-align:top;
       &.space{
           padding-top:1em;
       }
       figure{
           float:right;
           margin:0;
           .minical-mo{
               width:60px;
               height:15px;
               font-size:11px;
               line-height:15px;
               text-align:center;
               color:white;
               background-color:$c_main;
           }
           .minical-de{
               width:60px;
               height:45px;
               font-size:35px;
               line-height:45px;
               text-align:center;
               color:black;
               background-color:white;
               border-radius:0 0 5px 5px;
               -webkit-box-shadow: 0 5px 12px -5px $c_dk;
               -moz-box-shadow: 0 5px 12px -5px $c_dk;
               box-shadow: 0 5px 12px -5px $c_dk;
           }
       }   
   }
   td{
       color:black;
       font-size:.85em;
       padding:3px;
       vertical-align:top;
       &.space{
           padding-top:1em;
       }
       p{
           margin-bottom:1em;
           line-height:1.2;
       }
       &.link{
           overflow:hidden;
           a{
               width:100%;
               overflow:hidden;
           }
       }
   }
}

Answer №1

To ensure proper formatting of the .link element, please apply the following CSS properties:

white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
max-width:100px; /* modify as required */

These styles will truncate the link if it exceeds a certain length and display an ellipsis (...) at the end.

Answer №2

To solve a comparable issue, I managed to tackle it by restricting the length of the text string and displaying the full content in a tooltip. You can find more details about my approach in this blog post HERE.

Answer №3

Understood

td.link{
    overflow:hidden;
}
td.link a{
    display:block;
    overflow:visible;
    max-width:10px;
    white-space:nowrap;             
}

To prevent the anchor from influencing its column size, set a maximum width and allow overflow to be visible. Then hide overflow on the table cell.

A drawback of this approach is that text-overflow:ellipsis won't work since we are hiding block overflow rather than text overflow. It's a compromise I'm willing to make in this scenario.

If you have any ideas for getting text-overflow to function properly, please share them with me.

Appreciate all the input from everyone.

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 it possible to upload multiple files using JavaScript?

My JavaScript project can be found on GitHub. You can check out a live demo of the project here. The main goal for my HTML Button with id='Multiple-Files' is to enable users to upload multiple files, have them displayed in the console, and then ...

Is there a way to stop jQuery dragging functionality from causing the page to scroll unnecessarily

Whenever I drag an element from div1 to div2, the scrollbar in div1 keeps extending until I drop the element in div2. How can I prevent this extension without breaking the element being dragged? <div class="container-fluid"> <div class="row"> ...

Unable to transform Table layout into DIVs

My form for data input consists of labels with inputs, but the labels are localized so I am not sure about the length of text for different languages. To tackle this issue, I initially used a table layout: <table> <tr> <td> ...

Enhance the responsiveness of full-screen pop-ups

My current project involves creating a full-screen pop-up for a specific application. /* Custom Full Screen Popup */ .fullscreen-popup { position: fixed; top: 0; ...

Tips for locating the index of the previously selected active class

I am currently working on a slider and have made progress up to this point. However, I am facing an issue where I cannot proceed because I need to identify the index of the item from which I removed the last active class before the click event occurs. My ...

Resources for ExpressJS

New to ExpressJS and trying to figure out how to reference images stored in the /public/images/ directory in my /public/stylesheets/styles.css The code snippet below doesn't seem to be working for me: .home-bg { background-image:url('../ima ...

Is It Acceptable for CSS Code to Contradict Default CSS Code?

Imagine if my CSS looks like this: div { margin: 0; overflow: auto; padding: 1%; text-align: center; word-wrap: break-word; } This is supposed to be the default styling for all div elements. But what happens if there's another div with conflicting c ...

What causes Firefox (Mobile) to zoom out of my webpage?

After launching my webpage on Google Chrome mobile (android), everything loads perfectly. However, when trying to access the site using Firefox mobile (android), most pages load in a zoomed-out view. The issue is resolved by opening the drop-down menu, but ...

Using the CSS property 'clear' creates a significant gap in the layout

Using a div like this to clear space after floats: .clear { clear:both; } However, the formatting is getting messed up with extra space. Any ideas on how to fix it? Appreciate your help! ...

Challenge with Making Backgrounds Responsive on Android Chrome

I’m facing an issue with the responsive background on Android Chrome. It displays correctly on PC browsers like Safari, Firefox, and Opera, as well as in Firefox on Android. However, I am encountering a problem with Chrome on Android where it doesn’t a ...

How can CSS and JavaScript be used to strategically position two upright images next to each other within a dynamically resizing container?

Looking for a way to display two portrait images side by side within a flexible container with 100% width? The challenge I'm facing is accommodating varying widths of the images while ensuring they are the same height. <div class="container"> ...

Adjust the content column in the form to be mobile-friendly

Currently, I am coding in PHP and using Bootstrap. In my project, there are two columns - the LEFT column displays text, while the RIGHT column contains a form: Presently, when viewing on desktop, both columns are visible. However, on mobile devices, ...

Enhance the appearance of your Dojo TabContainer when viewing in Internet Explorer

Firefox seems to handle the following code without any issues: < div style="position:absolute;top:0px;margin-top:60px;bottom:0px;width:100%"> < div id="mainTabContainer" dojoType="dijit.layout.TabContainer" style="width:100%;height:100%"> {% fo ...

Looking for Protractor CSS functionalities nodes

I tried the code below but am having trouble locating the "Login" text using Protractor: <div _ngcontent-c2="" class="align-center"> <img _ngcontent-c2="" alt="Autoprax" class="ap-logo" src="/images/apLogoSmall.svg" style="width: 100%"> ...

Rearranging Twitter Bootstrap Grid Columns

Is it possible to rearrange columns in Bootstrap without using col-sm-pull-12/col-sm-push-12? I'm struggling to achieve the desired layout. Are there any alternative methods to accomplish this task? Check out this JSFiddle for reference. <div cla ...

Adjusting offcanvas height in Bootstrap based on content

.cursor-pointer { cursor: pointer; } <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="690b06061d1a1d1d09c13c809e9afbcfc1792efeff8">[email protected]</a>/dist/js/bootstr ...

JavaScript Canvas - Preserve Image Transparency

I have been trying to download a snapshot of a canvas using the code below: var strMime = "image/png"; var canvas = document.getElementsByTagName('canvas')[0]; var link = document.createElement("a"); link.href = canvas.toDataURL( ...

How to dynamically adjust font size using Javascript

Is there a way to adjust the font size of the left-column using JavaScript? <div id="left-column"> <a href="">1</a><br> <a href="">2</a><br> <a href="">3</a><br> <a href=""> ...

Tips for adjusting the maximum height of the column panel within the DataGrid element

I'm trying to adjust the max-height of a column panel that opens when clicking the "Columns" button in the Toolbar component used in the DataGrid. I am working with an older version of @material-ui/data-grid: "^4.0.0-alpha.8". https://i.stack.imgur.c ...

Change the Background of Your Body?

Here's the deal. I'm looking to create a cool effect where the background of the body slowly fades out and changes periodically in a loop using CSS and jQuery. Any suggestions on how I can make this happen? Appreciate your help! ...