Tips for placing a div at the bottom of a parent td element

In my project, I am facing a challenge in placing a <div> with a fixed height of 100px and full width (100% of the parent <td>) at the bottom of a <td>. The issue is that the content of the other <td>s may be larger than the browser's viewport height.

I have tried various solutions from resources like this, but they place the div at the bottom of the browser's viewport, not the actual <td>.

Edit: The current method I attempted, as per the provided link, was unsuccessful:

td {
    position: relative;
}
div {
    position: absolute;
    bottom: 0;
}

I am seeking an option using PHP, HTML, CSS or JavaScript (including jQuery) to correctly fix a <div> to the bottom of a <td>, taking into account the <td>'s total width.

Edit 3: Another issue arises when implementing the above solution - setting position: absolute; causes the width: 100%; to refer to the viewport width rather than the <td> width.

Edit 4: Here is the relevant code snippet from my page:

html:

<tr>
    <td id="content">
    </td>
    <td class="sidebar">
        <div class="internal">Notice</div>
    </td>
</tr>

css:

#content{
    height: 1000px;
}
.sidebar{
    width: 10%;
    min-width: 200px;
    position: relative;
}

div.internal{
    position: absolute;
    bottom:0;
    width:100%;
    height: 100px;
}

Link to jsFiddle for reference: Source

Answer №1

Check out this demo link

Here's how you can position the div at the bottom

td{
    position: absolute;
}

div{
    position: absolute;
    bottom: 0px;
}

LATEST UPDATE

I've included an example using your code with a functional demo

This solution has been tested on Chrome and IE, and it should give you the layout you desire.

UPDATE 2

For a table-based layout option, you can explore this: table layout example

UPDATE 3: exclusively using tables

If the previous suggestions didn't work for you, perhaps your code structure needs to be more organized. Consider using tables exclusively by nesting another table inside the designated cell like shown here: nested table in cell demo. While not ideal, it may be a simpler solution compared to using JavaScript and will likely be easier to maintain in the long run.

Answer №2

give this a shot

div.newClass{
    position: relative;
    top:0;
    width:50%;
}

and see how it looks.

Check out the example with the div positioned at the top of the page only.

JSFiddle

Answer №3

To implement this, you can try the following code:

<table>
    <tr>
        <td class="sidebar">
            <div class="internal">Important</div>
        </td>
    </tr>
</table>

Customize the look with CSS:

.sidebar{
width: 10%;
min-width: 200px;
height: 1000px;
background-color: green;
}
div.internal{
    position: absolute;
    height: 100px;
    background-color: yellow;
}

Add some functionality using Javascript:

$(document).ready(function () {
var $div = $('div.internal');
var $td = $div.closest('td');

$div.width($td.width() + 2);
$div.css('top', ($td.height() - $div.height() + 12) + 'px');
});

Check out the demo 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

Accessing the form element in the HTML outside of the form tag in Angular 2

I am attempting to achieve the following: <span *ngIf="heroForm?.dirty"> FOO </span> <form *ngIf="active" (ngSubmit)="onSubmit()" #heroForm="ngForm"> <div class="form-group"> <label for="name">Name</label& ...

Unable to send headers to the client in expressjs as they have already been set

After successfully logging in, I am trying to redirect to another page but keep encountering the error message "Cannot set headers after they are sent to the client". I understand that I need to place the res.redirect method somewhere else in my code, bu ...

Importing a JS file within a JS script

Currently, I am facing a requirement to dynamically include a .js file (more jQuery code) within a working jQuery script. Specifically, when my page gets authenticated, I need to add a specific script file. I am looking to accomplish this in ASP.Net MVC. ...

When using Ajax in Jquery and expecting data of type JSON, the response always seems

Looking to create a basic jQuery Ajax script that checks a user's discount code when the "Check Discount Code" button is clicked? Check out this prototype: <script> jQuery(function($) { $("#btn-check-discount").click(function() { c ...

Utilizing Pug for Passing Variables to JavaScript

I am working with a Pug view that displays a set of links to users. The user is already authenticated and their username and department are stored in session variables. I am able to pass these variables to the view using this code: res.render('landin ...

Leveraging an external React library to utilize .ogg files for audio playback specifically in the Safari

Hey there! I'm currently working on incorporating ogg-opus audio playback in a react app on Safari (since it doesn't support .ogg format). My project was initialized using create-react-app. I came across the "ogv.js" library, which supposedly h ...

What is the reason behind shadow dom concealing HTML elements when viewed in inspect mode?

https://i.stack.imgur.com/UZM7f.png Monday.com has implemented Shadow Dom to protect its source code. How can I work around this limitation? ...

Utilizing jQuery in your webpack configuration for optimal performance

I encountered some issues while trying to test a simple project that involves using a jQuery function with webpack. The errors occurred during the bundling process and are as follows: ERROR in ./~/jQuery/lib/node-jquery.js Module not found: Error: Cannot ...

Optimizing White Space in Firefox

Recently completed the construction of my new website, it appears flawless when viewed on Chrome. However, upon inspecting it on Firefox (OS), I noticed that there is an approximately 15px space at the bottom of the page. I am struggling to identify what m ...

"Using AngularJS to fetch data with $http and store it in an

Utilizing $http.get to retrieve data which includes MailID and SubscribedDate. The results are stored in $scope.subscriber. I am interested in extracting an array of all MailID values such as: ["<a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

What is the process for attaching an iterator to the name value of every element within a cloneNode?

Consider the following scenario: <div id="addNewMenuElementPart2"> Numerous elements with a name attribute are present here. </div> <div id="addNewMenuElementPart3Optional"></div> Additionally, t ...

Div in jQuery bounces upon page initialization

Let me clarify my question for better understanding. I am currently using JQuery animations on my website, and they are working well. However, when the page is refreshed, the divs containing the animations seem to jump around before settling in the correct ...

Tips for adjusting the thickness of the next/prev icons in the Bootstrap carousel

Exploring the world of HTML/CSS and Bootstrap. There's a carousel with these previous/next buttons : <button class="carousel-control-prev" type="button" data-bs-target="#testimonials-carousel" data-bs-slide="prev ...

Convert your Coffeescript loop that uses the range method into ES6 syntax

Disclaimer: Although I acknowledge the impact Coffeescript has had on the ES6 spec, I personally look forward to moving on from it. The following Coffeescript loop (written by someone else) if @props.total>1 for page in [<a href="/cdn-cgi/l/email ...

The error message "Property 'destroy' of undefined cannot be read in DataTables"

I need to develop a function that can create a new DataTable. If there is an existing table, I want the function to first destroy it and then create the new one. This is what I have so far: $.ajax().done(function(response){ Init_DT(response[& ...

Using jQuery to Drag: Creating a draggable effect on a div element

I recently posted a question, but I feel like I need to rephrase it to make it more general. Basically, I have an element that can be moved around and resized using jQuery. I used CSS to attach another div to the right of this element. Initially, when you ...

Track and log specific route requests with ExpressJS morgan feature

Hello, I am currently utilizing the NodeJS web framework Expressjs along with a middleware called morgan to log requests to a file. Here is my configuration: // create a write stream (in append mode) var accessLogStream = fs.createWriteStream(__dirname + ...

Tips for integrating CSS keyframes in MUI v5 (using emotion)

Hey there! I'm currently working on adding some spinning text, similar to a carousel, using keyframes in my React app. The setup involves MUI v5 with @emotion. Basically, I want a "box" element to show different words every few seconds with a rotating ...

Steps for creating a personalized popup window

Is there a way to create a custom dialog box that includes images, input fields, and more, similar to the design on this website? Any suggestions on what tools or methods I could use to achieve this? ...

Guidance on transferring servlet variables to an HTML page through redirection in Java

I am looking for a way to open an HTML page from my Java servlet and utilize the variables of that servlet to populate the form fields in the HTML page when it is opened. Below is the code snippet of my servlet: import java.io.*; import java.sql.*; impor ...