When a child SPAN surpasses the height of the parent TD/TABLE, trim it down

I am attempting to make my outer table/td clip the inner SPAN when the content of the span exceeds the height of the outer table, all while maintaining vertical and center alignment.

Instead of the current layout:

https://i.sstatic.net/s33q7.png

I want to achieve this design:

https://i.sstatic.net/vh4ah.png

You can view a live demo at: https://jsfiddle.net/xstatic/nksf9r71/14/

table {
  background: red;
  width: 300px;
  height: 100px;
  table-layout: fixed;
  word-wrap: break-word;
  border-collapse: collapse;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
}

table td {
  text-align: center;
  vertical-align: middle;
  height: inherit;
  overflow: hidden;
  border-collapse: collapse;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  max-height: 0px;
}

table td span {
  padding: 10px;
  overflow: hidden;
  height: inherit;
}
<table width="100%">
  <tr>
    <td><span>KITTENS DON'T ALWAYS GO TO HEAVEN</span></td>
  </tr>
</table>

Answer №1

Uncertain of any additional requirements, but the following code will generate the desired output:

table td div {
  height: 2rem; /* Adjust height as needed */
}
table td div div {
  margin: -0.5rem;
  overflow:hidden;
}

A wrapper div must be added:

<tr><td><div><div>KITTENS DON'T ALWAYS GO TO HEAVEN</div></div></td></tr>

Nevertheless, this method of displaying a table cell is unconventional and could lead to potential issues in the future.

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

Troubleshooting JavaScript's onchange Function Dysfunction

Here is the code snippet I am working with: <!DOCTYPE html> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> <script src="jquery-2.2.1.min.js"></script> <script src="slike.js"></script> ...

Unable to move up and down in my iframe

I am currently working on an Instagram page that is visible through an iframe. Everything seems to be functioning fine on my iMac, but I am facing an issue with scrolling on my iPhone and iPad? After reviewing my code, I couldn't find any hidden over ...

An issue with the font display

I'm having trouble with a specific font on my webpage and jsfiddle, even though it works fine on w3schools website. Here's an example on jsfiddle HTML <div> With CSS3, websites can finally use fonts other than the pre-selected "web-safe" ...

What is the best way to create an index for a user-provided value in a textbox

Looking for guidance on how to set an index to user-provided values in a textbox, append them to a table in a new row, and display that index in the first column of every row. I am unfamiliar with this type of functionality. $(document).ready(function() ...

JavaScript and CSS animations out of sync in terms of timing

I've been encountering some issues. I have an array containing 5 lines of text that change with a timer, but it seems that the css timer animation might not be synced properly or my @keyframes slidesdown setup could be incorrect. The delay between te ...

What is the best way to align a div with a td within a table?

I have a table and I inserted a div inside it, but now the alignment with the td is off. I applied display: inline-block to both the td and div elements, but the td only shifted slightly. How can I correct this? Here's my HTML code for the table : ...

Getting the chosen option from a dropdown list mapped in ReactJS

I am working on a dropdown select option that is linked to the data of an array object called 'template_titles'. Currently, the value in the dropdown corresponds to the title in the object. My goal is to be able to extract and use the selected va ...

Discover and transform any strings that begin with http & https into clickable links

Can I use jQuery to search a paragraph for all strings that begin with http & https and turn them into clickable links? I have my Twitter feed displayed on my website, but any lines starting with http & https are shown as regular text. Is it feasible to t ...

Organize images with overlays to the center of the page

I need help centering a group of pictures (a 3x3 table) on my webpage. I was able to center them before adding image overlays, but now the images are showing up in the top left corner of the page. How can I group and center them, and how do I specify the i ...

PyQt TreeView scrollbar obstructing the header

I've been experimenting with the QTreeView widget (instead of QListView) in order to have a horizontal header. Additionally, I wanted to use stylesheets to customize the colors and appearance of the header and scrollbars. However, there is an issue w ...

How to effectively extend the window.onload event handling function?

I've encountered a scenario where I need to incorporate my function, foo, into the existing window.onload event. However, there is already another function called bar assigned to the window.onload. Unfortunately, I don't have access to modify how ...

Mastering HTML5 Video: A guide to smoothly playing multiple videos in a loop fashion

Although similar questions have been raised in the past, none has successfully addressed this particular issue; they only provide partial solutions. The objective is as follows: We possess a collection of videos referred to as video1, video2, video3, vid ...

Step-by-step guide on transferring an HTML5 sqlite result set to a server using AJAX

Imagine I have a scenario where I receive a result set as shown below: db.transaction( function(transaction) { transaction.executeSql( 'SELECT col1, col2, col3 FROM table;', [],function(transaction, result){ //need to find a ...

The header that sticks on scroll is annoyingly blocking the content

I managed to create a sticky on-scroll header/navigation bar successfully. Here is how it looks now However, I encountered an issue. When it reaches the top, it automatically 'covers' the top part of my content, which has text on it, and I don& ...

Is there a way to extract shared properties within a Material UI style declaration?

I am working with a specific set of style rules that define different statuses: status_in_progress: { fontSize: 14, backgroundColor: theme.palette.success.dark, padding: 2, paddingLeft: 5, paddingRight: 5, display: "inline-bl ...

Can you explain the purpose of ExpiresAbsolute?

In the process of converting an ancient and poorly written ASP page to ASP.NET, I stumbled upon this particular line in the "head" section: <meta http-equiv="ExpiresAbsolute" content="0" /> Despite searching on Google, I couldn't find any mean ...

Position a dynamic <div> in the center of the screen

My goal is to design a gallery page with a list of thumbnails, where clicking on a thumbnail will open the related image in a popup div showing its full size. The issue I'm facing is how to center the popup div on the screen, especially when each pic ...

Explore a Wordpress HTML code

I own a WordPress website using the Photolux theme. My desire is to extract HTML elements such as titles and tags, but for some reason they are not visible. Just to clarify, I am not interested in reading the XML format. If anyone has any suggestions or ...

Integrating additional youngsters into the HTML DOM using Angular.js

I am working with a block of HTML that looks like this: <div id="parent"> <div id="child_1"></div> <div id="child_2"></div> <div id="child_3"></div> <div id="child_4"></div> </div> ...

When the mandatory option is chosen, the scroll snap type acts similar to proximity by enforcing

My goal is to have the main hero section of the website take up the entire screen, and when the user scrolls down, they are immediately brought to the main content with the hero section no longer visible. However, I am experiencing an issue where if I do a ...