Tips for setting the height of a div within a td to be 100%

I am struggling to make the orange divs in this example stretch out to match the height of the enclosing td element without explicitly setting the parent's height. I have tried using display: flex and align-items: stretch, but I can't seem to achieve the desired design. It seems like a simple task, but it requires a deep understanding of the CSS model that I unfortunately lack.

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

td {
  background-color: aliceblue;
}
<table style="width: 800px;position: absolute;">
  <tbody>
    <tr>
      <td>cell 1</td>
      <td>cell 2</td>
      <td>cell 3</td>
      <td rowspan="3">normal text in a td is using 100% height.</td>
      <td rowspan="3" style="height: 100%">
        <div style="background-color: orange;">a div with colspan inside a td is not using 100% height.</div>
      </td>
    </tr>
    <tr>
      <td>cell a</td>
      <td>cell b</td>
      <td>cell c</td>
    </tr>
    <tr>
      <td>cell x</td>
      <td>
        <div style="background-color: orange;">a div inside a td is not using 100% height.</div>
      </td>
      <td>
        <div style="width: 100px; height: 100px; background-color: lightgreen; padding: 8px">a large cell</div>
      </td>
    </tr>
  </tbody>
</table>

Answer №1

After stumbling upon a helpful comment, I was able to uncover this ingenious solution

<style>
    td {
        background-color: aliceblue;
    }
    table{
        height:1px;
    }

    .inner {
        height:100%;      
    }
</style>

<table style="width: 800px;position: absolute;">
    <tbody>
        <tr>
            <td>cell 1</td>
            <td>cell 2</td>
            <td>cell 3</td>
            <td rowspan="3">normal text in a td is using 100% height.</td>
            <td rowspan="3" style="height: 100%">
                <div class="inner" style="background-color: orange;">a div with colspan inside a td is not using 100% height.</div>
            </td>
        </tr>
        <tr>
            <td>cell a</td>
            <td>cell b</td>
            <td>cell c</td>
            
        </tr>
        <tr>
            <td>cell x</td>
            <td><div class="inner"style="background-color: orange;">a div inside a td is not using 100% height.</div></td>
            <td><div class="inner" style="width: 100px; height: 100px; background-color: lightgreen; padding: 8px">a large cell</div></td>
            
        </tr>
    </tbody>

</table>

This incredible revelation provided the perfect fix

https://i.sstatic.net/1dm96.png

Upon grasping the concept that assigning a dummy height to the parent's table triggers the css rules, it all began to make sense. Although somewhat unconventional, as long as it yields results, I'm content.

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

Enable vertical scrolling on a container of undetermined height

Can a vertical scroll be implemented on a container with an unknown height using flexbox? The use of max-height is not feasible, as it would limit the height to a specific number that may not work for all screen sizes. Here is a basic example of what is ...

Guide on creating frozen columns in an Angular 2 table with the ability to scroll through multiple columns

Within my table, there are 3 columns that must always remain on the left side. Additionally, there is a column containing a grid where each element represents an hour of the day, requiring it to be scrollable. I have attempted various proposed solutions, ...

Conceal and reposition divs based on device with Bootstrap's responsive utilities

Utilizing Bootstrap to design a layout that adapts to desktop, tablet, and mobile screens. The desired output is depicted below: In order to achieve this, three divs were created: <div class="row"> <div class="col-md-3">Text</div> & ...

Utilizing Python for Extracting Data from the NFL Section on ESPN's Website

Looking to extract historical NFL game results from the ESPN website using Python for further analysis? Currently, facing an issue with adding dates to the extracted data before saving it in a CSV file. Below you can find the link to the NFL webpage where ...

Changing color based on AngularJS condition using CSS

My HTML code looks like this: <div> <i class="glyphicon glyphicon-envelope" style="margin-top: -50px; cursor:pointer; color: #1F45FC" ng-click="createComment(set_id)"> </i> Route <center> ...

Would you like to learn how to set an auto-play video as the background in a webpage section, similar to the one found on http://www8.hp.com/in/en/home.html?

I was browsing the HP-India website and noticed they have a cool autoplay video in the background of a section below the header. I would love to recreate something similar on my own website. Any tips on how to achieve this? ...

Unable to vertically scroll on a position fixed element

I recently created a unique VueJS component that enables vertical scrolling. Within this component, there are two elements each with a height of 100vh. At the bottom of the component is a fixed position div. Interestingly, when I try to scroll down using m ...

Issue with the execution of Javascript code. Edit required

After creating a registration form that allows users to input their information for registration, I encountered an issue where if certain fields were left empty or if the user name was unavailable or the email address was already registered, a warning mess ...

Unable to use jQuery to choose an item from a dropdown menu and reveal a hidden text box

Seeking assistance in displaying a paragraph with text and a textbox when a specific option is selected from the dropdown menu on my form. Previously used code for radio buttons, but encountering issues with this scenario. Any guidance would be greatly app ...

How can I overlay text on top of an image?

I want to create a design where half of the text overflows and overlays the image on the right side. How can I achieve this using a Grid item? I've tried using "absolute", "relative", and "z-index" positions, but they don't seem to work in the MU ...

I am looking to update a WordPress site every 10 seconds to keep it current

Currently, I am working on a plugin and my goal is to automatically refresh the widget every 10 seconds. Can someone guide me on how to achieve this? I need to figure out a way to call the widget function at regular intervals in order to refresh the conte ...

``There seems to be an issue with the alignment of items in the

I am fairly new to using css and bootstrap and I am currently working on integrating a carousel into my angular web app. I copied the code from the bootstrap site but I am facing challenges in aligning everything properly. Additionally, the image slides do ...

Clicking on text triggers image display

My journey in coding is just starting and I have a good understanding of the basics of HTML, CSS, Javascript, and jQuery. I am trying to make an image appear when I click on text but struggling with the implementation. I'm working on a restaurant web ...

Creating a line with CSS is a straightforward process that involves using properties

I am trying to achieve a yellow line effect similar to the image shown using CSS. I have managed to create line holes so far, but I'm struggling with creating vertical straight lines. Here is an example of my current code: https://i.sstatic.net/MqRUE ...

Using Jquery and CSS to add a class with a 1-second delay when the mouse enters

I have successfully implemented the addClass function in my code, but I'm encountering issues when attempting to use delay or setTimeout functions. It's important to note that I'm avoiding the use of webkit attributes in CSS. If anyone has ...

What is the best way to shift the lower section to align with the right side of the rest of the headers and text blocks?

Help needed with moving the Uni section to align it beside other paragraphs and headers. Tried using float left but no luck so far. Any suggestions would be appreciated! Check out the code here <div class ="container"> <div id="education" class ...

Is it possible to use JavaScript to make a CSS animation mimic the behavior of a :hover effect?

My CSS animation looks like this: HTML: <div class="container" id="cont"> <div class="box show"></div> </div> CSS: .container { width: 100vw; height: 100vh; } .box { position: absolute ...

Tips for sending a JavaScript parameter to PHP

I am implementing a pop-up modal window that retrieves data from the myForm and saves the email field value to a JavaScript variable in index.php. How can I pass this JavaScript value to PHP and display it using echo, without refreshing the index.php windo ...

Explore creating a dial number using React

Hey there, I'm currently working on developing a component. Just to clarify, I am not using react-native for this project. Instead, I would like to utilize React to scroll a number similar to how an image scrolls. The goal is to have the number smoo ...

Conceal the input field prior to making a selection from the dropdown menu

I have implemented a drop-down menu for selecting dependencies, similar to how it functions in JSFiddle. $('#user_time_zone').on('change', function() { dateCalender = $(this).val(); if (dateCalender == 'Single Date') { ...