Precise placement in a table cell with dynamic height

I need to align two divs inside a table cell, one at the top and the other at the bottom.

Check out this demo on jsFiddle http://jsfiddle.net/davew9999/3Mwz5/11/ to see the HTML structure I am working with. Here is the code:

HTML

<table>
<tbody>
    <tr>
        <td>
            <div class="cell">
                <div class="top">The content of this div varies in length so setting fixed height wouldn't work. It could be long or short.</div>
                <div class="bottom" >This bottom div should always stick to the bottom of the table cell, also dynamic in height.</div>
            </div>
        </td>
        <td>
            <div class="cell">
                <div class="top">Not much text here.</div>
                <div class="bottom">Just like above, this bottom div should adjust to its content's height.</div>
            </div>
        </td>
    </tr>
</tbody>
</table>

CSS

tr {
    vertical-align: baseline;
}
td {
    padding: 10px;
}
.cell {
    position: relative;
}
.bottom {
    position: absolute;
    bottom: 0;
}

Many solutions available involve setting a height on the wrapper div (class "cell"), but that won't work for me due to dynamic content.

I attempted calculating the td element's height upon loading and applying it to the "cell" div. This worked until browser window resize changed the table cell's height. Resizing triggers many events, making it impractical for over 200 td elements in IE8.

Splitting the content between rows might be a temporary fix, but I'm seeking a CSS or better CSS+JavaScript solution than what I've tried.

Answer №1

Unfortunately, I am unable to test this out right now because I am currently in a lecture using my iPad.

By setting the position to relative and the bottom to -1, you should be able to fix an element to the absolute bottom or vice versa.

Additionally, setting the height of the parent element may force a cell to have the same height as the td (does 100% accomplish this?).

Once again, I cannot test this at the moment due to issues with JFiddle on iPad's Chrome/Safari browsers.

Have you considered whether or not Twitter Bootstrap's scaffolding classes can handle this for you?

There are also resources available on scaffolding and responsiveness in Twitter Bootstrap here.

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

"Implementation of Google+ button causing the appearance of a horizontal scrollbar

Adding Facebook and Twitter sharing buttons was easy, but now I'm having trouble with Google+. No matter where I place the code on my page (using a Bootstrap grid), it always adds 2-3 pixels on the right side, creating a horizontal scrollbar: <div ...

In the context of resizing elements within a scrolled div, CSS divs with margin auto may not always be perfectly centered

I am encountering an issue with centering divs within another div with overflow:auto; initially, all divs are centered using margin: 0 auto; however, when I use jQuery to resize the last div, a scrollbar appears (as expected) but the other divs remain in t ...

Issue encountered when attempting to use an HTML document as a blueprint for generating additional HTML documents with the

I am currently working on an exercise that involves creating four different files: index.html, home.html, about.html, and contact.html. The objective is to utilize jQuery's .load function to load the other three HTML files within index.html while stil ...

How to vertically align radio buttons with varying label lengths using Angular and Bootstrap 4?

Is there a way to properly align radio buttons with variable length labels? When each label has a different length, the radio buttons appear misaligned. How can this be fixed? <div class="row"> <div class="form-check form-check-inline" *ngFor="l ...

Stay afloat at the bottom of the webpage without using xhtml

Currently working on Moss 2007 and in need of creating a floating button at the bottom of the screen. This button should move down as I scroll down and up when scrolling back up. Although it can be easily achieved with xhtml, the challenge lies in not bei ...

What is the process for placing a component on the right side of the sidebar?

Here is the code snippet I am working with: <template> <div class="main"> <sidebar /> <router-view /> </div> </template> The sidebar has a width of 260px. I need to ensure that any comp ...

Validation for optional fields in asp.net mvc 5

In my asp.net mvc 5 application, I have a form with some fields that are optional and not required to be filled. Despite trying different approaches, I keep getting a warning message stating that these fields are required. [Required(AllowEmptyStrings = t ...

Experiencing difficulty adjusting the width of a Tumblr post with JavaScript or jQuery?

Calling all coding experts! I've been working on customizing a Tumblr theme, and everything is looking good except for one issue. I'm struggling to adjust the width of photos on a permalink (post) page. Check out this link: You'll notice t ...

Issue with image magnification on Internet Explorer 9 using the Cloud Zoom plugin extension for Joomla

Recently, I've been utilizing a Joomla plugin called cloud zoom to enhance our gallery by providing an image magnification effect when hovering over the large image. You can see it in action on this link here. While it works flawlessly on most browser ...

How to properly adjust image size in a flex-direction column layout - tips and solutions

My mission is to place an <img> with text blocks above and below it inside a container of specified height. The exact heights of the text blocks and image are unknown. After extensive searching, my colleague provided a useful solution by using the ...

Utilizing SQL and Python within a web environment

Can you help me with a question? I have created Python scripts in Spider where I pull data from SSMS using SQL commands and then manipulate it using Python. Now I want to run these codes on a webpage or other online platforms so that others can use them ...

Bootstrap 3 Implementation of a Clear Navbar

I'm trying to create a transparent navbar using the code below: <div class="navbar navbar-default navbar-fixed-top" style="top:50px; background:transparent;"> <div class="navbar-inner"> <div class="container"> <ul cla ...

How to vertically center Bootstrap 4 columns while maintaining uniform height

Having trouble with aligning bootstrap 4 columns' height and vertical alignment? Check out this JSFiddle to see the issue. I'm working on designing a layout with items in both desktop and mobile views, all within borders. The challenge lies in ...

Repeatedly triggering the Jquery Dialog Event

When I open a calendar plugin in jquery dialog, I encounter a recurring issue. Every time I close and reopen the dialog, my calendar event onDayClick triggers multiple times – twice, thrice, and so on. <div id="show_calendar"> <div class="c ...

a non-breaking space within a hyperlink

While working on the subnavigation of a website, I encountered an issue with the link Suite «Mont Blanc», which was pulled from the backend. The desired format for this link was:       Suite «Mont Blanc» However, t ...

jQuery text slideshow not working properly when a <br> tag is present

I'm looking to develop a basic text slideshow that smoothly transitions between phrases and loops continuously. However, I've run into an issue where the slideshow malfunctions when I add a line break in the text. It only seems to work properly w ...

Tips for importing a JavaScript file from a URL and initializing a class in a React component

I am looking to incorporate the PitchPrint app into a React website. They offer a tutorial for vanilla HTML/JS integration here. Following their instructions, I included script tags with links to jQuery and their app file in my index.html file. I then crea ...

Bootstrap 4 menu toggle malfunctioning

After extensively searching for a solution to this issue on multiple threads in Stack Overflow, I am baffled as to why it is not working. The example below (taken from a thread on this topic) functions correctly in jsFiddler, but fails to work when served ...

Is it possible to customize the CSS styles of a jQuery UI modal dialog box?

Having trouble with my CSS styles not applying to a dialog modal added to my website using jQuery UI, even when using '!important'. I suspect that the predefined jQuery or UI CSS styles from a CDN link are preventing me from overriding them. The ...

Images overlaying text and each other in a cascading arrangement

I need help arranging an icon with a number on top in the left corner of a div container, alongside an image to the right. While it displays correctly on desktop, the mobile view overlaps the image on the right and the text on the left. Here is a snippet ...