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

Is there a way to update the color of a button once the correct answer is clicked? I'm specifically looking to implement this feature in PHP using CodeIgniter

Within my interface, I have multiple rows containing unique buttons. Upon clicking a button, the system verifies if it corresponds to the correct answer in that specific row. The functionality of validating the responses is already functional. However, I a ...

Title with lower border shorter than width

Looking to achieve an underline effect with a bottom border that is narrower than the width of the h2 title. Though I typically avoid uploading images, here is one to provide further clarification of my question: ...

Displaying videos in full screen using HTML5

I am attempting to create a fullscreen webpage with a video using the following code: <video id="backgroundvideo" autoplay controls> <source src="{% path video, 'reference' %}" type="video/mp4"> </video> ...

Using scope in ng-style to manipulate a portion of a CSS property value in Angular

I've been attempting to add a border using ng-style, but I'm struggling to figure out how to concatenate the value from the scope variable. None of the methods below seem to be working for me: <div ng-style="{'border-top' :'1p ...

CSS Challenge: How to crop an image without using its parent container directly

I'm currently facing a complex CSS challenge that I can't seem to solve. I want to create an image controller (two-by-two layout on two lines) that can display: The top-left image in full size, The top-right with horizontal scrolling, The botto ...

Tips for getting rid of the glowing effect on MUI slider thumbs when they are in focus

import * as React from "react"; import Box from "@mui/material/Box"; import Slider from "@mui/material/Slider"; function valuetext(value) { return `${value}°C`; } export default function RangeSlider() { const [value, se ...

Design a captivating Profile Picture form using HTML and CSS styling

In my form, I am looking to include a user's Profile picture which should be displayed in either a circular or rectangular shape. Initially, the image area will show a black background or a placeholder image. When the user clicks on this area, they sh ...

Revolutionizing Interaction: Unveiling the Power of Bootstrap 3

Would you be able to assist me in customizing buttons to resemble a typical dropdown link? <div class="dropdown"> <button class="btn dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">Dropdown <span class="caret"&g ...

Adjust the button's hue upon clicking it

The current function is operational. Upon pressing the button, it toggles between displaying "click me" and "click me again". However, I desire the button to appear blue when showing "click me" and red when displaying "click me again". <!DOCTYPE html ...

"Padding has not been recognized as a valid input value

I'm struggling with getting padding to be accepted by the browser when I style a card using Material-UI. const useStyles = makeStyles((theme) => ({ cardGrid: { padding: '20px auto' }, })) Unfortunately, the browser is not recogni ...

Looking for help with aligning an icon to the right side of my text

I'm struggling with aligning the icon to the right of the quantity. When I use float:right, it places the icon at the far right of the cell instead of next to the text. Is there a way to get it to be on the right side of the text but directly adjacent ...

Display a pop-up directly below the specific row in the table

I am working on creating a table where clicking on a row will trigger a popup window to appear right below that specific row. Currently, the popup is displaying under the entire table instead of beneath the clicked row. How can I adjust my Angular and Bo ...

Tips for creating sliding header content alongside the header

Is it possible for the content in the header to scroll up, displaying only the navigation list and hiding the logo when a user scrolls on the website? Currently, while the header background slides up, the content within the header remains in place. I feel ...

What could be the reason for my new course not being recognized?

Looking to modify the behavior of a button where, when clicked, it hides a specific div element, changes its text display, and toggles between classes using addClass/removeClass for subsequent click events. Unfortunately, the intended functionality is not ...

Numerous websites with scroll-based navigation

I am currently building a unique website that includes scrolling in various directions without the use of a horizontal scrollbar. The design is similar to this image: https://i.stack.imgur.com/Ex2Bf.jpg. It is a one-page website where vertical scrolling ...

Fade background position rollover effect

I'm facing a challenge with animating my background image using background positioning. The CSS is functioning correctly, but when I attempted to enhance it by adding jQuery for a rollover effect, the animation isn't working as expected. Can anyo ...

Tips for CSS and jQuery: Show link when hovered over and switch the visibility of a content div

I'm facing an issue with a link in the horizontal navigation bar. When a user hovers over it, I want another div to slide down just below it. The problem is that using the .toggle method doesn't work as expected. It continuously toggles the div e ...

Troubleshooting problem with CSS scaling on smartphones

I'm attempting to create a website (the first one I've ever designed) dedicated to my girlfriend's cat. However, when viewed on a mobile device, it doesn't look good. I've made an effort to adjust the meta viewport tag, but it does ...

Unfortunately, I am currently unable to showcase the specifics of the items on my website

I am trying to create a functionality where clicking on a product enlarges the image and shows the details of the product as well. While I have successfully implemented the image enlargement, I am facing challenges in displaying the product details. Below ...

"Any tips on maintaining the blue color of my dropdown link when it is selected as active

I'm struggling to keep the bootstrap accordion dropdown link blue when it's active. I've tried different methods but none seem to work. What am I missing? Here's my code: <div class="visible-sm visible-xs" id="accordion" role="t ...