When HTML tables are nested and set to a height of 100%, the second table will overlap the first table

Here is an example for you to try out! Simply copy and save the code below as an .html file, then open it in your browser:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<table style="width:100%;height:500px" border="5" >
<tr>
   <td>
       <br /><br /><br /><br /><br /><br />
    <table border=1 style="width:100%;height:100%">
      <tr>
       <td>
            <br />test<br />
       </td>
      </tr>
     </table>
   </td>
</tr>
</table>

After running the code, you will notice that the second table overlaps the first due to the added line breaks. If you want the second table to expand to the full remaining height without removing the "height" element on the first table, how can this be achieved?

This scenario represents a simplified version of a larger, more complex HTML structure.

Answer №1

Here is a snippet of code that has been tested and proven to work:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<table style="width:100%;height:500px" border="5" >
    <tr><td height="75px"></td></tr>
    <tr>
        <td>
            <table border=1 style="width:100%;height:100%;">
                <tr>
                    <td>
                        test
                    </td>
                </tr>
            </table>

        </td>
    </tr>
</table>

If you encounter any issues with overlapping, simply adjust the td height as needed. The problem was due to the inner table having a 100% height setting, causing it to not properly expand within the outer table which had a fixed height.

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

What is the best way to keep an image fixed at the top while scrolling, but have it disappear when the page reaches the footer?

I am in need of creating a unique Bootstrap 4 layout that involves an image staying fixed to the top after scrolling down until it reaches the bottom of the header. When the page is further scrolled down and the footer comes into view, the image should sta ...

Modify the background color of column headers in a Material UI DataGrid as you scroll down vertically

In my React(NextJS) project using material UI, I have implemented tables (DataGrid component from material UI) with distinct background colors in the column headers, as shown below: https://i.sstatic.net/zd3Iu.png However, I encountered an issue where ra ...

Issues with PHP and HTML form functionality?

I am currently working on a form that collects the user's name (input) and IP address (hidden input), and then saves this information to a text file. However, I am facing an issue where the IP address is not displayed on the page for the user to see, ...

Is it acceptable to store HTML in a content database?

I am considering storing HTML in a database, but I want to ensure it is safe. If I restrict who can submit the content, do you think it would be secure enough? My question is quite straightforward. I run a platform that provides video tutorials and variou ...

"Utilizing Bootstrap 4: Wide text causes columns to stack on top of

My website has a layout with three columns: col-auto on the left, col in the middle, and col-auto on the right. The col-auto columns display skyscraper ads (600x160) while the col column contains text. However, when the text inside the col column is wide, ...

Troublesome issue with Internet Explorer and Safari: The .click() function does not work for input type="button" in Jquery

Is there a way to ensure that the input type="button" functions properly with jquery function .click() in Internet Explorer and Safari? While it works seamlessly in Mozilla, Chrome, and Opera. For instance, when the button is clicked, a hidden div should b ...

The progress bar for uploading a file is causing issues with the redirect function in the

I am currently facing an issue with my file submission form and progress bar in JavaScript. The progress bar is interfering with the controller, preventing it from redirecting back home with the link. I have tried removing window.location.href="/"; but thi ...

Navigating pages in tinymce editor

Currently, I have implemented TinyMCE as the editor for my PHP-based website. However, I am facing a challenge in integrating pagination within the editor. My goal is to allow users to input long content that will be displayed across multiple pages inste ...

Using jQuery to locate a JavaScript variable is a common practice in web development

I recently created a JSFiddle with buttons. As part of my journey to learn jQuery, I have been converting old JavaScript fiddles into jQuery implementations. However, I seem to be facing a challenge when it comes to converting the way JavaScript fetches an ...

What could be causing the problem with my CSS background-image being referenced correctly?

Everything seems to be in order: background-image: url(./dir/img.jpg); However, I encounter a 404 error when attempting to reference an image using this approach: index.html <div style="--url: url(./dir/img.jpg);"></div> css backg ...

Discovering elements that are shallower than a chosen selector

I'm currently developing a jQuery plugin designed to facilitate the management of form collections. This plugin is intended to incorporate buttons for adding, removing, moving up, and moving down within the collection. In every collection's r ...

Load pages using ajax with conditional if statements

I am currently developing a website that relies on ajax to load its inner pages. However, I need certain groups of pages to have background and container width changes as well. Is there a way for me to use conditional if statements to modify the class or ...

What is the best method for placing a single character from a user's quote into a table?

this is an example of some HTML code <section class="insertionCitation"> <label>Quote:</label> <input #quote (keyUp.Enter)='validateQuote(quote.value)'> </section> `- how can I display one letter ...

Populate a table with data from a list using C# and asp.net

I am currently working with a class called Car, which has attributes like Model and Year. I also have a list of objects of type Car, stored in List<Car> carList = new List<Car>(). My goal is to display this list within an HTML tag, but I am uns ...

ngx-bootstrap encountered an issue: TypeError - _co.openModal is unavailable as a function

Just starting out with ngx-bootstrap, I was attempting to create a modal using the instructions from this site : However, I encountered the following error: ERROR TypeError: _co.openModal is not a function Here are some code snippets: //app.component ...

Utilize both the width and max-width properties to effectively wrap text within JOptionPane

I'm not well-versed in HTML/CSS, so please bear with my limited knowledge. I'm currently developing a GUI where I need to display a message dialog in case of an error. The error message could be either short or lengthy. I've implemented the ...

What could be causing the DIV elements to not align side by side?

<div id="dvFirst" class="mainSecond" style="background: #6FA5FD;"> <div id="leftdiv3" class="leftdiv">Client: </div> <div id="rightdiv3" class="rightdiv"><asp:DropDownList ID="ddlCliNewMsg" AutoPostBack="t ...

Add formatting to specific list items within the Ui Fabric Nav element

https://i.sstatic.net/BcCbj.png Please take a look at the provided screenshot. In the list, some items are marked with an eye icon to indicate that they are hidden and not important for the user's immediate attention. However, this icon seems to have ...

Tips for creating a fixed navigation menu that remains visible while scrolling without any items disappearing

I have been working on my web design lately and have been trying to utilize as much CSS as possible without relying on JavaScript. I encountered an issue when designing my navigation menu, which is supposed to remain fixed at the top of the page. Here is a ...

A small space underneath the <a> element nested within a <li> tag within a navigation bar

As a new programmer, I am currently working on creating a navbar. However, I have encountered an issue where there are small gaps underneath the user when my cursor hovers over it. There is a white gap under the user element. I expect that the hover back ...