Ways to maximize the use of vertical space within an element

Check out this code snippet on JSFiddle by clicking here. This excerpt of code showcases a table with a unique layout:

<table style="height:100%">
    <tr height="20"><td></td></tr>
    <tr>
        <td>This gray cell fits all available height of table</td>
    </tr>
    <tr height="20"><td></td></tr>
</table>

The table consists of three rows, with the middle row adjusting its height to fit that of the entire table. The solution for this design was inspired from this source.

The challenge arises when trying to add overflow-y scrolling to the middle cell. It appears that the minimum height of the content inside the cell affects this feature. Is there a way to enable vertical scrolling (overflow-y:auto) or if not, how can a similar layout be achieved using div elements?

UPDATE: A working example is available at http://jsfiddle.net/haGWe/6/. However, it's still intriguing to explore alternative implementations using divs.

Answer №1

Check it out right here.

To implement this solution, simply include a div within your td element with a specified height (I used 20px) and apply overflow: auto.

Answer №2

Enclose the middle row's contents in a div element and apply CSS to that div.

<div class="widget">
<table cellpadding="0" cellspacing="0">
    <tr class="widget-header">
        <td>20 px above</td>
    </tr>
    <tr class="widget-content">
        <td><div id="myDiv">This gray cell takes up all available height of the table. What happens when more text is added here? Scroll bars appear.</div></td>
    </tr>
    <tr class="widget-footer">
        <td>20 px below</td>
    </tr>
</table>
</div>

.widget{
    position:absolute;
    min-width:200px;
    width:200px;
    outline:1px solid gray;
    right:50%;
    top:20px;
}
.widget > table{
    height:100%;
    width:100%;
}
.widget-header{
    height:20px;
}
.widget-content{
    vertical-align:top;
    background:gray;
}
.widget-footer{
    height:20px;
}
#myDiv
{
    height:40px;
    overflow-y:scroll;
}

http://jsfiddle.net/2YvG6/

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

invalid audio element

I'm currently working on building an audio player with a visualizer feature. However, when I try to initiate the audio player by clicking on the input button, my debug console keeps showing this error message: Uncaught (in promise) DOMException: Fa ...

Stop the replication of HTML/CSS styles during the extraction of content from a div

Is there a way to prevent the copying of CSS properties, such as font styles and sizes, when content is copied from a div? I want only the plain text to be copied to the clipboard, without any formatting applied. ...

An error has occurred in the Shadow Dom due to the inability to access the property 'style' of an

While working on a component using shadow DOM, I encountered the following error in the console: "Cannot read property 'style' of undefined". This issue seems to be related to my HTML code in PHP. The main challenge I am facing is figuring out ho ...

Executing an AngularJS function within a form element using the ng-submit directive

I have created an AngularJS function that I intend to call in my form tag. However, when I use this function in my html form within the ng-submit attribute, it does not redirect or perform any action. When I click on the button, nothing seems to happen a ...

Managing primary and secondary color schemes within Material Design Components for Web - a complete guide

Exploration I delved into the realm of Material Components (MDC) for Web and found myself utilizing CDN for hosted CSS and JavaScript libraries: https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css https://unpkg.com/mate ...

Guide on triggering an open modal when clicking a link using jQuery

Creating a modal popup has always been my goal. After designing the CSS to style it, I found myself stuck as I lack knowledge in JQuery or JavaScript to code the functionality that animates and opens the modal upon clicking a button or link. Despite search ...

I am encountering some problems with the Drop Down navigation feature on my Bootstrap website. Does anyone know how to properly center the drop down menu?

Hey there! So, I've been trying to fix the wonky drop-down menu on my website, but everything I've attempted so far hasn't worked. I've tinkered with float, margin, and a bunch of other CSS techniques, but no luck. Someone suggested usi ...

Split the content of a textarea before it reaches the next element

I have a textarea in my html file and I am trying to prevent the text from overlapping with an emoji icon button. I would prefer not to use a z-index for the emoji as it may cause issues with other elements on the page. Below is the code snippet: HTML & ...

Having difficulties with DIV elements

Having some difficulty creating a webpage with divs. The site I'm working on is similar to the old Myspace, so CSS can't be used in the code. Attempting to create tables using DIV elements but facing some issues. This is what my page currently l ...

Is there a way to maintain the original style of an HTML element when printing it?

When attempting to print an HTML element using window.print();, the original style is not preserved. How can this issue be resolved? printInvoice() { var mywindow = window.open("", "PRINT"); mywindow.document.write("<html>"); mywindow.d ...

When HTML elements are unable to access functions defined in separate JS files

After successfully resolving the issue, I am still curious as to why the initial and second attempts did not work: The problem lay with an HTML element connected to an event (myFunction()): echo '<button class="btn remove-btn" onclick="myFunction( ...

Adaptable background image - smoothly resize/reposition

Is there a way to smoothly resize my background image instead of it jumping abruptly? Currently, when using media queries, the background image goes from 900px to 300px in height instantly at a certain point. How can I make this transition more gradual? ...

Clicking on the icon image that features a Background Video will trigger the video to play in a popup window originating from the same location

A background video is currently playing on the site. When the play icon is clicked, the video should start playing in a popup. The video should start playing continuously from the exact moment and position where it is clicked. Check out the example here. ...

The functionality of Bootstrap popover is not functioning properly

I'm trying to activate a popover when users hover their mouse over a div. Can I use a popover with a div, or am I missing something in my code? Here's what I have: <div class="grid-item content-text" data-toogle ="popover" data-content="Lorem ...

Challenges of relative positioning with dynamic height based on content

Hello! I'm trying to achieve this https://i.stack.imgur.com/Q6lXP.png In this case, there are 3 divs. The top one will have a width of 100% and a height of auto, with relative positioning. The second div is similar, but I plan to add some dummy text ...

Problems encountered with the navigation on mobile devices

Seeking advice on debugging a non-functioning mobile side menu implementation. The main site, a WordPress site, works perfectly. However, the offsite white label version does not. All HTML has been copied to the white label and necessary CSS and scripts h ...

Grid item overlay

Currently, I am facing an issue with React where I am attempting to place an overlay on top of each grid item in a grid. Despite trying multiple approaches, the overlay appears beneath each grid item instead of over it. Even setting the position: absolute ...

Is there a way to display the true colors of a picture thumbnail when we click on it?

In my project, I attempted to create a dynamic color change effect when clicking on one of four different pictures. The images are displayed as thumbnails, and upon clicking on a thumbnail, it becomes active with the corresponding logo color, similar to t ...

If I choose a different option from the dropdown list, I would like a textbox to appear

Hey there, I have a list of industries and one of the options is "Other". When a user clicks on "Other", a text box should appear for them to specify. I'm struggling to make this work using Django AJAX. Any help would be appreciated! <div class ...

Challenges with moving images in Unslider

There seems to be an issue with the unslider-arrows on the unslider banner. The images are not sliding properly when transitioning to the next image without user input. Instead, they resize from small to full size starting at the top of the .banner div. ...