Why isn't the CSS display property of table-cell working when I set height and overflow to hidden?

I am having trouble clipping an element when its children's content is too large, particularly within elements styled with display:table-cell. Check out this example on JsFiddle:

JSFiddle Example

.table{
    display: table;
    table-layout: fixed;
    width: 100%;
    height:200px;
}
.cell{
      display: table-cell;
      vertical-align: top;
      position: relative;
      height:200px;
      overflow:hidden;
}
.container{
  height:100%;
  background-color:red;
}
.container img{
  display:block;
}
<div class="table">
    <div class="cell">
        <div class="container"> 
          <img src="http://img5.imgtn.bdimg.com/it/u=172690696,3532821463&fm=206&gp=0.jpg" />
           <img src="http://img5.imgtn.bdimg.com/it/u=172690696,3532821463&fm=206&gp=0.jpg" />
            <img src="http://img5.imgtn.bdimg.com/it/u=172690696,3532821463&fm=206&gp=0.jpg" />
        </div>
    </div>

If anyone can help me identify the issue, that would be greatly appreciated. Thank you!

Answer №1

To ensure functionality, the table must be set to position:relative and the table cell item to position:absolute in your code. Additionally, I have removed the unnecessary height: 100% for the container. You can view the preview and fiddle here.

.table{
    display: table;
    table-layout: fixed;
    width: 100%;
    height:200px;
    position: relative;
}
.cell{
      display: table-cell;
      vertical-align: top;
      position: absolute;
      height:200px;
      width: 100%;
      overflow-y:scroll;
      overflow-x: hidden;
}
.container{
  background-color:red;
}
.container img{
  display:block;
}
<div class="table">
    <div class="cell">
        <div class="container"> 
          <img src="http://img5.imgtn.bdimg.com/it/u=172690696,3532821463&fm=206&gp=0.jpg" />
           <img src="http://img5.imgtn.bdimg.com/it/u=172690696,3532821463&fm=206&gp=0.jpg" />
            <img src="http://img5.imgtn.bdimg.com/it/u=172690696,3532821463&fm=206&gp=0.jpg" />
        </div>
    </div>

Answer №2

Modify your CSS display style.

.table{
    display:block;
    width: 100%;
    height:200px;
}
.cell{
  display:block;
  vertical-align: top;
  position: relative;
  height:200px;
  overflow:hidden;
}
.container{
  height:100%;
  background-color:red;
}
.container img{
  display:block;
}

Check out the fiddle here

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

Styling trick: Positioning a paragraph next to a span filled with SVG icons

I am facing an issue with the alignment of a set of SVGs contained within a <span> element appearing below a <p> element. I want the span to line up with the text 'Question 1'. Methods I have attempted: No conflicting margins or pa ...

Checkboxes and the adjacent selector

Looking for a way to change the background color of a label when the corresponding checkbox is checked? Take a look at the code snippet below to see how it can be done: .viewbutton { height: 48px; width: 48px; background-color: #FFFFFF; border-r ...

Is there a single function that can handle multiple sliders sharing identical options?

Currently, I am utilizing jQuery UI to generate 6 sliders with identical options for a survey. I am curious if there exists a method to merge all these sliders into one function while maintaining the ability to operate them individually? If such a soluti ...

Tips for designing table rows with varying column lengths using CSS and JavaScript

I am facing an issue while populating my table with data from a list. Currently, the table cells are being filled from left to right, but I want them to be populated from top to bottom. Unfortunately, I am unsure how to achieve this using a list method. ...

Tips for choosing elements based on a specific attribute (such as fill color) in D3.js using the SelectAll method

I have various sets of circles on a map - 10 red circles, 10 blue circles, and 10 green circles. Is there a way to use d3 selectAll or select to specifically choose only the red circles? Are there any alternative methods for achieving this? The color of ...

What steps are involved in updating the default value in ngx-daterangepicker-material?

Is there a way to change the default value of gx-daterangepicker-material from yesterday to the last 7 days? If so, how can this be achieved? Here is the code snippet: export class CustomRangesComponent implements OnInit { selected: any; alwaysShowCalenda ...

Tips for ensuring the accurate retrieval of prop values by waiting for the value to be set

Encountering an issue with the .toUpperCase() method within one of my components, resulting in the following error: TypeError: Cannot read properties of undefined (reading 'toUpperCase') This problem seems to stem from a race condition in fetc ...

Issue with PrestaShop not displaying page content after adding jQuery

After updating to the latest version of Presta Shop, I encountered an issue. When I inserted the following code: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"> jQuery(document).ready(function(){ ...

Enhancing user experience by implementing dynamic text box functionality that triggers ajax load for dropdown options using a combination

Here is the task I need help with, along with the code snippet: I want to enable the author select box when both the start and end dates are filled out. The author names should be fetched dynamically from the database based on the selected start and end ...

Issue with conditions in window.setTimeout function

I've been grappling with a website that features a loading page lasting 5 seconds, during which users can choose to activate autoplay or not. However, even after implementing a condition in my code, the autoplay feature continues to run unexpectedly. ...

Customize the appearance of the v-autocomplete component in Vuetify

How can I style the autocomplete component to only show words that begin with the letters I'm typing, rather than all words containing those letters? Also, is there a way to display the typed letters in bold without highlighting them? https://i.sstat ...

Animate the text before it fades away

Could someone help me figure out how to make my text animations work correctly? I want to show and hide specific text with animation when buttons are pressed, but I'm having trouble implementing the hiding animation. Any guidance would be appreciated. ...

What is the method to include a data attribute without a value in a React createElement?

When adding a div to the DOM using React, it can be done as follows: React.createElement("div", { className: "test", "data-test": true }); The resulting HTML should look like this: <div class="test" data-test> </div> I am wondering where ex ...

Troubleshooting CSS rendering issues on Chrome browser

Currently in the process of developing a new website based on an old template. The site appears as intended in IE, Safari, and Firefox, but for some reason Chrome is not rendering any of the css. Just to clarify, none of the links are functioning at this ...

Ways to display/trigger a dropdown list from the top in Kendo Multiselect module for Angular

On my page, I have implemented a Kendo Multiselect dropdown list. Currently, when clicked, the list expands top to bottom (downwards) but for my specific requirements, I need it to display bottom to top (upwards). I referred to the Kendo UI Angular docume ...

Image can be centered, but unable to center div in IE7

When trying to center an element both vertically and horizontally, everything seems to be working correctly except for one issue I'm facing in IE7. I am able to center an img vertically but not a div. What style is being applied by IE to the image tha ...

JavaScript is failing to execute the DELETE SQL transaction

I've been attempting to clear out my html5 local sql database, but for some reason, it's not working as expected. Below is the code I'm using, and no matter what I try, the alert always shows that the length is greater than 0. Any ideas why ...

What is the meaning of a "hook" in the world of HTML?

During a recent interview, a developer asked me about the "hooks" Angular uses with HTML. I admitted that I was not familiar with the term "hook," despite my extensive experience in web development over the past two decades. While I have some ideas of what ...

Guide on sending a JavaScript variable as a URL parameter in Django

I need to pass a radio ID to my view, but I'm struggling with how to do it using the GET method in the URL: html: <a href="{% url 'maintenance_issue_fix' %}?radio_id=checked"> <img src="{% static 'images/ma ...

Encountering the issue "error TS2339: Property 'user' is not available on type 'Object'."

issue TS2339: The property 'user' is not found on the type 'Object'. export class UserAuthentication implements OnInit { user = new BehaviorSubject<Userlogin>(null); constructor( private route: ActivatedRoute, private rou ...