The height setting for the table does not appear to be effective

Here is the structure of my HTML:

<div class="wrapper">
<table>
<tbody>
<tr>
<td>some content</td>
</tr>
</tbody>
</table>
</div>

The style for my wrapper looks like this:

.wrapper{
color: #444444;
    height: 165px;
    line-height: 135%;
    margin-top: 10px;
    padding-bottom: 10px;
    width: 270px;
}

and my table only has a defined width along with some inherited styles :

.wrapper > table {
    width: 100%;
}
table {
    background-color: transparent;
    border-collapse: collapse;
    border-spacing: 0;
    max-width: 100%;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

What I am trying to achieve is having my table consume the maximum height of its parent element, which is .wrapper with a height value of 165px, but the table's height does not seem to decrease as expected.

My ultimate goal was to set a vertical overflow on the wrapper so that if the table exceeds the height of .wrapper, users can scroll. Any ideas or hints on what might be missing here?

When I adjust the table's height to be greater than 190px, it responds by growing larger. However, when I reduce it to smaller sizes like 165px or below 190px, it does not seem to react accordingly.

Answer №1

Adding height: 100% to the table style allows it to inherit the height from its parent element:

.container > table {
  width: 100%;
  height: 100%;
}

Check out the demo here: http://jsfiddle.net/1QWDB/

Keep in mind, the inherited height of the table is the specified height of the parent (e.g. 200px), not the height including padding or margin.

Answer №2

To make it completely tall, set the height to 100%. Right now, the height is not specified.

Keep in mind that tables often have their own way of handling heights. If the content doesn't fit, they can be a bit resistant. ;)

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 Internet Explorer 7 - unable to align button to the right using float property

My webpage features a button and a footer, but I am unable to get the button to float right. Here is the code snippet: <div style="float: right;"> <asp:Button ID="btnSubmit" OnClick="btnSubmit_Click" runat="server" Text="Save" CssClas ...

Determine if the data in an HTML table should be spanned when it

I'm facing a scenario where my HTML table contains duplicate data in a particular column, as illustrated below I am looking to automatically merge the cells of rows in the HTML table if the data in them is identical, similar to the table displayed be ...

Is there a way to relocate the collapse button to the bottom after it has been clicked?

I have been using Bootstrap to design a expandable card that can be expanded when clicked. I am currently using the collapse feature, but I am facing an issue where the button remains in its original position, whereas I want it to move to the bottom of the ...

Filtering arrays using Vue.js

I have developed a sample e-commerce website to showcase various products to potential customers. The website boasts features like filters, search functionality, and sorting options to enhance the user experience. However, I've encountered an issue sp ...

The navigation bar initially fills the width of the screen, but does not adjust to match the width of the table when scrolling

I've spent the last 2 hours playing around with CSS, using width:100% and width:100vw, but nothing seems to be working. Currently, the navigation bar fits perfectly across the screen on desktop browsers, so there doesn't seem to be an issue ther ...

Swap the content of one div with another div using client-side code only

Currently, I am in the process of developing my personal website. To enhance user experience, I have implemented a vertical navigation bar on the left side of the page. My goal is to replace the content of a specific div with content from other HTML files ...

Removing the hash from the URL

My website built with Bootstrap consists of two main pages: index.html impressum.html I have successfully implemented page jumps within the index.html page and would like to access these page jumps from the impressum.html page as well. The functionalit ...

Switch up the background image when hovering over it

Could the proportions of the image be contributing to the issue at hand? #menu { background: black; width: 100%; height: 45px; } #menu ul { text-decoration: none; list-style-type: none; } #menu li { text-decoration: none; display: inline; font-size: ...

What type of modelfield in django can store the duration of a video playback? Alternatively, how can a TimeField be used without an

It's surprising that I haven't found a solution on SO yet, but my current challenge involves storing information when a user taps/clicks on my video player. I am currently saving the current playback time in a TimeField as shown below: class Ta ...

Tips for Modifying the Color of a Progress Bar with Angular Directive

I am trying to incorporate an angular progress directive into my application. Although I have found a progress bar directive that serves the purpose, I am struggling to modify the color of the progress bar. I would like to assign a custom color to the pro ...

What is the best way to manage excessive content when printing an HTML page?

Struggling with My Test Project Images () I am in the process of creating a printable test project, however, I am facing an issue when the page content becomes lengthy. I would like the related question to appear on the next page below my header section. ...

Combine rows with the same value in the first column of an HTML table

My HTML table has dynamic content, and I need to merge rows in the first column only if their values are identical. You can see an image of the table here. Specifically, if the values in the first column match, those rows should be merged together while le ...

Using PHP to redirect upon clicking a link

My issue involves directing users to another page or form and saving the button they click as a value when selecting a CRN (course number). <table class="table table-bordered table-hover table-striped"> <thead> ...

The locator for the span class cannot be found or interacted with in Selenium

Here is the HTML code snippet for a span element: <td class="header-logout-btn"> <a href="logout.htm" class="btn switch-btn"> <i class="fa fa-times"></i><span class="hidden-xs">Home</span> </a> </td> I ...

Ensure that newly added elements are aligned with the settings of the slide's

I've encountered an issue with my jQuery slider that affects a div's CSS on slide. Everything works as expected, except when I add a new div, the settings from the slider aren't applied to the new div until the slider is moved again. HTML ...

execute php function when form is submitted

Hello, I am attempting to create a code using this PHP function: <?php function generateRandomString($length = 6) { return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/str ...

When a nested CSS Grid is inserted into an HTML table element, it causes horizontal overflow

     Generating an invoice dynamically with a CSS grid poses some challenges. To maintain a specific format, I need to define the number of rows and columns in advance along with column widths. Using template rows and columns for this purpose restrict ...

Vertically align the content within a div

Here is what I have been working on: http://jsfiddle.net/yisera/2aVpD/ I am trying to vertically center a div inside the .jumbotron-special container. I attempted using display: table; on the parent element and then implementing display:table-cell on th ...

``Display text in the center of a column when viewed on mobile

I am facing some challenges when trying to center text within a specific section of my webpage, particularly in the mobile view. This section is identified by the class about and is contained within a container-fluid div. I also encountered an issue where ...

What is the best way to use AngularJS to distinguish tab headings from their corresponding content sections?

Currently, I am working on an angularjs project where I am using the uib-tabset directive to display tabs. My goal is to have a left panel that remains consistent across all tabs. This requires me to insert a div either before or after the uib-tabset direc ...