Placing information on the opposite sides of a table cell

I am currently working on a monthly calendar table where each cell displays the date in the top left corner and has a "+" button in the bottom right corner for adding content to that day. Everything works fine when all cells have the same height, but it breaks down when the row heights vary due to different amounts of content.

For reference, you can view my progress on JSFiddle: http://jsfiddle.net/FLVh6/

Here is an example of the table layout:

<table>
<tr>
    <td>
        <div>1</div>
        <div>Content goes here</div>
        <div><input type="button" value="+" /></div>
    </td>
    <td>
        <div>2</div>
        <div>Content goes here</div>
        <div><input type="button" value="+" /></div>
    </td>
</tr>
<tr>
    <td>
        <div>3</div>
        <div>Content goes here</div>
        <div><input type="button" value="+" /></div>
    </td>
    <td>
        <div>4</div>
        <div>Content goes here.  The problem surfaces when the row stretches due to excess content, causing the button alignment to shift.</div>
        <div><input type="button" value="+" /></div>
    </td>
</tr>
<table>

Below is the CSS code I've used so far:

table {
    border-collapse:collapse;
    width: 300px;
}

td {
    padding: 5px;
    border: 1px solid black;
    width:50%;
    vertical-align:top;
}

td div:first-of-type {
    font-size:large;
    font-weight:bold;
    float:left;
}

td div:not(:first-of-type) {
    clear:left;
}

td div:last-of-type {
    float:right;
}

Answer №1

Include the following CSS code:

td{
    position:relative;
}
input{
    position:absolute;
    right:0;
    bottom:0;
}

Make sure to assign a specific class to your buttons to avoid impacting all inputs.

Keep in mind that this styling will not allow text to wrap around the input field.

Answer №2

The Power of Proper Positioning:

table {
    border-collapse:collapse;
    width: 300px;
}

td {
    padding: 5px;
    border: 1px solid black;
    width:50%;
    vertical-align:top;
    position:relative;
}

td div:first-of-type {
    font-size:large;
    font-weight:bold;
    position:absolute;
    top:0;
    left:0;
}

td div:not(:first-of-type) {
}

td div:last-of-type {
    position:absolute;
    bottom:0;
    right:0;
}

Please take note of the adjustments made to eliminate floating elements and incorporate proper positioning.

Answer №3

To position it at the bottom right of the container, try using absolute positioning. Ensure that the parent container is set to relative for correct functionality.

td div:last-of-type {
    position: absolute;
    bottom: 0;
    right: 0;
}

Take a look at this demonstration:

http://jsfiddle.net/FLVh6/1/

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

Space between flex content and border increases on hover and focus effects

My code can be found at this link: https://jsfiddle.net/walshgiarrusso/dmp4c5f3/5/ Code Snippet in HTML <body onload="resize(); resizeEnd();"> <div style="margin: 0% 13.85%; width 72.3%; border-bottom:1px solid gray;"><spanstyle="visibilit ...

Linking a Wordpress submenu to a specific section of a page

I am utilizing a Wordpress menu to act as the primary navigation for my website. Each main item in this menu is a Page Type that redirects to other existing pages, with one of them containing submenus made up of custom links. These custom links' URLs ...

Eliminate the flickering effect on the dropdown menu

Is there a way to eliminate the annoying 'flicker' effect on my menu? Whenever I click on 'Dropdown 1', I notice that Test 1 and Test 2 flicker. My assumption is that this is due to my use of the !important declaration. Any suggestion ...

Position the Bootstrap footer element at the bottom of the page

On a custom HTML page that I created, I decided to include a footer using Bootstrap. In this example, it demonstrates how the footer can be positioned at the bottom of the page without being placed inside a container element (directly within the body eleme ...

Is there a way to eliminate the menuArrow from a Select widget in gwt-bootstrap3?

In my current project, using gwt-bootstrap3, I have been attempting to conditionally remove the menu arrow from a Select box. I have experimented with various methods such as: <select:Select ui:field="fieldName" name="fieldName" b:id="fieldName" showM ...

What is the best way to ensure an image within a Bootstrap 5 column scrolls along with the page, but does not go past

How can I ensure that the image inside "fixedContainer" follows scrolling without going below the end of <div class="col-lg-8">, especially when the sidebar has a large amount of data and requires scrolling? <link href="htt ...

Setting a div's background using JavaScript works flawlessly on jsfiddle.net, but encounters issues when implemented in actual code

contains the files you need. For reference, here is the link to the code on I have attempted to remove all unnecessary elements from the actual project, but it has not made a difference. document.getElementById("image").style.backgroundImage = "url(" + d ...

Selecting options from the Gmail dropdown menu

I'm attempting to create a dropdown menu similar to the one in Gmail using Bootstrap. However, I have encountered 2 issues: 1- I am unable to click on the input checkbox to select all 2 - I would like it so that if I select all, the input gets sele ...

The battle between Hover, Focus, and Blur modes intensifies

My goal is to implement 4 different effects on an element: When hovering over the element. When moving away from the element. When focusing on the element. When blurred. However, I'm encountering a conflict where when I focus on the element, the ...

Implementing a dynamic header image that adjusts its resolution based on the device and pixel density for

After finishing a design in Sketch, I have 3 unique layouts with header images displayed below: To ensure the height is consistent and to crop the image appropriately on different devices, I export the following images from Sketch: dog-header-mobile-1x.p ...

Switching the default browser for npm live-server

When I use the npm live-server package to preview my website as it changes, it keeps opening in Edge even though Chrome is set as my default browser on my system. I attempted to use the command suggested on the npm website: live-server --browser=chrome H ...

What steps do I need to follow in order to perform a particle design simulation on my laptop

Recently, I attempted to utilize some of the particle designs featured on this website https://speckyboy.com/particle-animation-code-snippets/, but encountered difficulties. I have included both the stylesheet and javascript files, yet the design does not ...

I am experiencing an issue with the initial for-loop in my code as it is not

Upon clicking the start button, the score button, as well as the try again or correct button, are not being updated. Can someone help me figure out what's wrong? I believe the issue lies within this section of the code: for (i=0; i<5; i++) { do ...

Trouble with Setting a Background Image in Ionic with Javascript and Angular

I'm having trouble getting my background image to display in this Ionic project using CSS. It works when I embed it directly into the HTML, but that's not an ideal solution. I vaguely recall something about using base64 for images, but I'm n ...

Adjust the size of the image obtained from the JSON data

I am currently working on parsing JSON data which includes an image field that I want to adjust to a specific size. Despite my many attempts at tweaking the code, I seem to have lost track of why it is not functioning as desired. JSON var items=[]; ...

Arranging particular placement

How can I position my links to the right of the second photo (opus1) and slightly below the first photo (coverPhoto)? I've tried various methods but haven't found a simple solution yet. <!DOCTYPE html> <html lang="en"> <head ...

Drop down menu alignment issue: unable to center menu on the page

My dropdown menu is misaligned and not centering on the page, even after multiple attempts to fix it using HTML and CSS only. I have refrained from using JavaScript or JQuery for this issue. CSS Code: <style type="text/css"> /* STYLING FOR DROPDOWN ...

css - adjust flex box to cover half of the screen and increase its size

I'm having trouble getting my CSS Flex-box to stretch the full height of the right side of the screen from the center. I want it to cover the entire right half of the screen at full height. https://www.cajsoft.co.uk/test/visitor2.html Any help with m ...

Creating flexible items with a 1:1 ratio and ensuring that the padding on the left and right of the flex container remains consistent

Whenever I adjust the size of the window, the flex-container ends up with uneven padding on the left and right, which is less than ideal. So, I am looking for a way to allow the flex-item to resize when the window size changes, ensuring that the conta ...

In Bootstrap cards, image overlays are always displayed on top of the image

I'm struggling to understand why I can't get the image in this HTML snippet to appear anywhere other than on top. Despite my attempts to adjust z-index, use !important overrides, and try other methods for hours, I haven't been successful. My ...