Lack of consideration for height within tables positioned absolutely

In the case of an absolutely positioned element with display: table, if the height is explicitly set and the content exceeds this height, the element will adjust to wrap around the content rather than maintaining the specified height value.

#main {
  width: 100px;
  height: 29px;
  position: absolute;
  top: 20px;
  left: 200px;
  border: 1px red dashed;
  display: table;
  table-layout: fixed;
  border-spacing: 0;
  border-collapse: separate;
}

#child {
  display: table-cell;
}
<div id="main">
  <div id="child">Custom Text With Validation:</div>
</div>

Answer №1

When a table cell does not respect its parent's height, it can cause the entire table to expand unnaturally. This issue is similar to how the table cell does not adhere to the max-height property.

To address this issue, there are two solutions available. One option is to apply position: absolute to the child element.

#main {
  width: 100px;
  height: 29px;
  position: absolute;
  top: 20px;
  left: 200px;
  border: 1px red dashed;
  display: table;
  table-layout: fixed;
  border-spacing: 0;
  border-collapse: separate;
}
#child {
  position: absolute;
  display: table-cell;
}
<div id="main">
  <div id="child">Custom Text With Validation:
  </div>
</div>

Another approach is to insert an additional element inside the child and set the height on that element.

#main {
  width: 100px;
  height: 29px;
  position: absolute;
  top: 20px;
  left: 200px;
  border: 1px red dashed;
  display: table;
  table-layout: fixed;
  border-spacing: 0;
  border-collapse: separate;
}
#child {
  display: table-cell;
}
#child div {
  height: 29px;
}
<div id="main">
  <div id="child">
    <div>Custom Text With Validation:</div>
  </div>
</div>


Adding overflow: hidden to the table will help contain any excess content more effectively.

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

Issue with fixed positioning on iPad devices

A unique feature we implemented on our site is a small control that is positioned at the bottom of the screen. However, upon viewing the site on an iPad, the control does not stay fixed at the bottom but rather floats in the middle. What's the issue ...

WP Highlighted Image

I'm facing a small issue where the featured image on my posts is not displaying in the desired size. I want the featured image to match the total width of the post, but it keeps showing up in its original size. I'm clueless about how to fix this ...

Assistance with Parallax Mouse Movement, Using JQuery, HTML, and CSS

As a newcomer to JQuery, I decided to experiment with creating a parallax background effect using the mousemove function. By utilizing event.pageX to generate a variable for adjusting the background position, I was able to achieve the desired result. Alth ...

Responsive Bootstrap breadcrumbs for mobile devices

I'm struggling to make my bootstrap tabs mobile-friendly. While I like their appearance on desktop, I find that they don't look great when stacked on top of each other on mobile devices. Is there anyone who can provide some CSS tips on how to sh ...

How to Resolve the Issue of Projectiles Not Converting into an Image?

When I attempted to convert my projectile class into an image, an error occurred. Here is the error message: File "C:\Users\Habib\Desktop\PYTHONGGAME\py.py", line 320, in <module> bullet.draw(window) File "C:\Us ...

How can I enhance the appearance of the WordPress pagination numbers with a stylish border

Is there a way to apply a border around the WordPress pagination that starts from the first number and ends at the final number in the pagination sequence? The current structure of the WordPress pagination includes: <a class="prev page-numbers">< ...

The preventDefault() function is not functioning properly on the <a> tag

As a JavaScript beginner, I decided to create an accordion menu using JavaScript. Although I was successful in implementing it, I encountered a bug in my program. In this scenario, uppercase letters represent first-level menus while lowercase letters repr ...

Overlaying a parent container DIV on top of its child elements

My JavaScript scrolling view is quite intricate, enclosed within a DIV. The elements inside have event handlers for mouseover and mouseout to manage the scrolling behavior, as well as clickable links. Currently, I am in need of a semi-transparent image th ...

Alert: The attempt to include_once(headerSite.php) has encountered an error as the file does not exist in the specified directory

I'm a beginner in PHP and encountering the following errors: Warning: include_once(headerSite.php): failed to open stream: No such file or directory in C:\xampp\htdocs\dbtest\index.php on line 3 Warning: include_once(): Failed ope ...

Issues with the functionality of the contact form

I have recently purchased a new template that comes with a contact form featuring ajax and validation. I have tried to implement my script, but it doesn't seem to be working. I suspect there might be an issue on the server-side with my script. Can any ...

The aesthetic of react-bootstrap and material ui aesthetics is distinctive and visually appealing

As I develop my web application, I have incorporated react-bootstrap for its React components based on Bootstrap. However, wanting to give my project a customized look inspired by Material design, I came across bootstrap-material-design. I am curious if I ...

When navigating back, the Bootstrap Multistep Form breaks down

Tools I'm currently utilizing: HTML, CSS, Javascript, Bootstrap 3 Library / Package in use: https://codepen.io/designify-me/pen/qrJWpG Hello there! I am attempting to customize a Codepen-based Bootstrap Multistep Form from the provided link abov ...

I need to generate table rows using v-for and include a unique value in the 'id' attribute of each row

I am creating table rows dynamically in a view using Flask data. <tr id="<% file.id %>" v-for="file in fileList"> <td><img class="thumbnail_preview" src=""></td> <td><% file.filename %></td> <td> ...

Aptana Studio 3 fails to detect PHP code embedded within an .html file

When writing code, such as: <!DOCTYPE html> <html> <body> <?php echo "My first PHP script!"; ?> </body> </html> After <?php, I am encountering a red X icon error indicating that a ">" is missing at the end of t ...

Is there a way to use selenium to extract data from a webpage if the table is not formatted with the standard HTML 'table' tag?

I am currently attempting to extract the data from the tables that appear when selecting "Branches", a city, and a district from this specific website: Progress has been made in writing the code to navigate through each city and district: from selenium.we ...

Interactive HTML5 map featuring geo tagged points

Seeking an HTML5-based tool to efficiently display a zoomable, panable map (similar to Google Maps) and incorporate a circle at a specific location upon clicking a button on a webpage. Any suggestions for HTML5-compatible frameworks or would JQuery be the ...

Applying CSS transition delays to multiple images

I'm having trouble implementing a transition delay in my CSS. I've tried adding it in various places but it doesn't seem to be working as expected. This is my CSS: .imageBox { position: relative; float: left; transition ...

Creating ngModel dynamically with *ngFor in Angular 2: A guide

I've been struggling with this for the past couple of days - how can I have a new ngModel for each iteration within an *ngFor loop? The idea is that I load a list of questions, and within each question there are 2 propositions. Here's the HTML: & ...

Deleting a button from a list item or array in Angular 12

Having some trouble removing a list item with the click button, I've tried a few options but nothing seems to be working. Can anyone offer assistance? I need to remove a list item from my users array when clicked. Below is the Typescript code and cor ...

What techniques can I use to achieve a seamless transition using Javascript and CSS?

I'm striving for a seamless CSS transition. The concept of transition had me puzzled. Even though I utilized the setTimeout method in JavaScript to make my CSS functional, it lacks that SMOOTH feel! Check out my code below. function slideChange( ...