Unraveling the mystery behind table cells failing to wrap their content when set to 100% height

Original inquiry (REVISED)

CSS: Why does a table-cell sibling with a height of 100% exceed the body of the table-row?

Experimenting with CSS tables, I am striving to achieve an evenly spaced column layout.

  • I aim to have an "aside" on the left side that occupies 100% of the page's height.
  • To the right of the "aside," I intend to place a "header" above the main content.
  • Both the "header" and the "main" should extend to cover 100% of the page's height.
  • The entire layout should expand in height as the content within it grows.

Here is an example of my test: https://jsfiddle.net/264z0ovf/

I set the "aside" as a table-cell and set the height of "main" to 100%. This resulted in "main" exceeding the body of the table-row at the bottom.

Can you clarify why "main" overflows the "body" table-row when its height is set to 100%?

I did not anticipate this overflow. I expected "main" to fill the remaining space below the "header" or for the table to expand and encompass the entire height.

html,
body {
  margin: 0;
  height: 100%;
}

html {
  display: table;
}

body {
  background-color: #0000ff;
  display: table-row;
}

aside {
  background-color: #00ff00;
  display: table-cell;
}

header {
  background-color: #909090;
}

main {
  background-color: #ffffff;
  height: 100%;
}
<html>

<body>
  <aside>ASIDE</aside>
  <header>HEADER<br>AND SOME CONTENT</header>
  <main>MAIN</main>
</body>

</html>

Too Long; Didn't Read (TL;DR)

I understand that percentage heights are calculated based on the parent's height.
Therefore, if "main" has a height of 100%, it translates to 100% of the "body."

Adjacent to the "header" is a sibling anonymous table-cell that should wrap around both "aside" and "main." Consequently, the row of the table-body should also expand as its cells grow.
Reference: https://www.w3.org/TR/CSS21/tables.html#anonymous-boxes

Any table element will automatically generate necessary anonymous table objects around itself

Another example where "main" does not overflow the table can be found here: https://jsfiddle.net/80a53fvs/

  • I introduced a div table with a height of 100% to enclose both "header" and "main".
  • I switched "main" to act as a table-row while keeping its height at 100%.

This configuration causes "main" to occupy the remaining height under the "header" without overflowing the table.

html, body {
  margin: 0;
  height: 100%;
}

html {
  display: table;
}

body {
  background-color: #0000ff;
  display: table-row;
}

aside {
  background-color: #00ff00;
  display: table-cell;
}

div {
  display: table;
  height: 100%;
}

header {
  background-color: #909090;
}

main {
  background-color: #ffffff;
  height: 100%;
  display: table-row;
}
<html>
  <body>
   <aside>ASIDE</aside>
    <div>
      <header>HEADER<br>AND SOME CONTENT</header>
      <main>MAIN</main>
    </div>
  </body>
</html>

Answer №1

added

body {
 overflow: hidden;
}

html,
body {
  margin: 0;
  height: 100%;
}

html {
  display: table;
}

body {
  background-color: #0000ff;
  display: table-row;
  overflow: hidden;
}

aside {
  background-color: #00ff00;
  display: table-cell;
}

header {
  background-color: #909090;
}

main {
  background-color: #ffffff;
  height: 100%;
}
<html>
  <body>
    <aside>ASIDE</aside>
    <header>HEADER<br>AND SOME CONTENT</header>
    <main>MAIN</main>
  </body>
</html>

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

Could Angular be automatically applying margins or padding to my component?

I'm encountering a minor issue.. I'm attempting to create a "Matrix" to construct a snake game in angular, but there seems to be an unremovable margin/padding. Below is my code: <!-- snake.component.html --> <div id="ng-snake-main&q ...

The checkbox appears unchecked, yet the content normally associated with a checked checkbox is still visible

As the title suggests, I am encountering an issue with my code. Here is the snippet: $('#somediv').change(function() { if(this.checked) { $('.leaflet-marker-pane').show(1); } else { $('.leaflet-marker-p ...

Enhancing ag-grid with alternating row group colors following row span

My data structure is shown below: https://i.stack.imgur.com/fy5tn.png The column spanning functionality in ag-grid is working for columns 1 and 2 as expected. However, I am looking to implement alternate row colors based on the values in column 2 (animal ...

How to format values in a textarea using AngularJS

Is there a way to address the following issue without replacing \n with other values? A user can input a description for something in a textarea and include line breaks. In the controller, there is a value called description which includes a string ...

Searching for link href and text in a PHP DOM document

Within an html tag, there are the following elements: <ul class="l1nk"> <li class="dir online"> <a target="_blank" rel="nofollow" href="https://sample.com/embed/2882015?ref=7Qc" t ...

Exploring JSON Object with ng-disabled in AngularJS

One unique feature of my web application is the ability to add new users (username + password) through a form. To prevent duplicate usernames, I have a JSON object called l_usernames defined in a controller named UsersController. This object contains all u ...

Guide on aligning a child div directly beneath its parent without specifying the parent's height

I want to position a div beneath its parent in a way that mimics a menu opening below it. Currently, I attempted using right and top, but the child div ends up overlapping the parent. If the parent had a defined height (rather than top: 0 as shown below), ...

Is there a way to customize the scrollbar color based on the user's preference?

Instead of hardcoding the scrollbar color to red, I want to change it based on a color variable provided by the user. I believe there are two possible solutions to this issue: Is it possible to assign a variable to line 15 instead of a specific color lik ...

Disappearing act: CSS3 transform - rotate makes font vanish

When applying a simple css3 transformation rule to an html element which contains various other elements like h1, h2, inputs, and img, I encounter the following issue: div{ -moz-transform: scale(1) rotate(-3deg) translateX(0px) translateY(0px) skew ...

How can you apply color to {{expression}} text using AngularJS while also keeping all the text on a single line?

After writing the following code, I noticed that when I enter text into the input box, an output appears. However, I am now trying to find a way to color the output text while keeping it on the same line. <script src="https://ajax.googleapis.com/ajax ...

Issue: Invalid element type detected: expected a string (for built-in components) or a class/function

Currently, I am in the process of learning how to make API calls using React Redux. I decided to practice by implementing an example in StackBlitz. However, I encountered an error after selecting a channel and clicking on the 'Top News' button. C ...

A foolproof guide to effortlessly incorporate an image into your banner while ensuring its perfect alignment even with varying screen widths

I'm facing an issue with adding a photo to the banner on my webpage. Currently, the photo remains in the same position within the banner regardless of screen size. However, I want it to stay right above my logo even when the screen size changes. How c ...

Saving HTML form field data through erb for persistent storage

Encountering an issue with erb while trying to populate the value of an HTML form field. The situation involves a scenario where the user has inputted an incorrect password and we want them to retain their name/email address information without having to r ...

Ways to change the class attribute on button click with jquery

I attempted to change the class attribute here, but unfortunately was unsuccessful. Can anyone provide guidance on how to toggle the class value successfully? <button id="mybt" class="fa fa-plus"></button> <script> $("#m ...

Place a date picker in the recently added row

How can I add a date picker to a newly appended row using jQuery? $(document).on('click', '.fa-plus-square', function () { var newRow = $('.installment').html(); $('.payment').append('<div class="form- ...

By using .innerHTML to create an element, the validation of HTML form fields can be circumvented

After inserting a form field with standard HTML validation constraints (pattern & required), using the .innerHTML property does not trigger validation. While I understand the difference between creating an element with .innerHTML and document.createElement ...

Using Aframe and JavaScript to create split id animations

I am currently working on an Aframe WebVR app and trying to develop a function that splits this.id into two parts, assigns it to a variable, and then uses setAttribute. This is the code I have: AFRAME.registerComponent('remove-yellow', { init ...

Browsing HTML Documents with the Click of a Button

After collecting JSON data from a SharePoint list, I am currently in the process of creating an HTML Document. At this point, I have completed approximately 80% of the expected outcome. Due to Cross-Origin Resource Sharing (CORS) restrictions, I have hard ...

Using HTML to position multiple lines of text alongside an image

I have multiple lines of content and hyperlinks. Additionally, there is an image included. I am looking to have the text aligned on the left with the image on the far right, positioned next to the text. While I attempted to use flexblocks to center everyt ...

Having trouble retrieving text from input element using selenium

In my Java/Spring application, I have created an HTML file with radio buttons populated from a database. Now, I am working on writing a Selenium test case to click the radio button. The values for these radio buttons are stored in an Excel sheet that I am ...