Tips on ensuring that a span element is positioned at the bottom of a table cell

Is there a way to position the span element at the bottom of a table cell in HTML:

Here is the code snippet I'm working with:

<td>
    <span class='cat-otsikko'>Product title</span>
    <span class='cat-hinta'>Product price</span>
</td>

I am trying to always have the cat-hinta appear at the bottom of the td regardless of the length of the product title above it. How can I achieve this setup? I want the product price to be consistently displayed at the bottom, independent of the length of the product title.

UPDATE:

An attempt using Fancy's code was unsuccessful. Here is my complete code (tuotteet is the table class):

.tuotteet tr{
border:1px dashed gray;
}

.tuotteet td {
width:30%;
border-right:dashed 1px gray;
border-bottom:dashed 1px gray;
padding:5px 2px 5px 2px;
border-top:dashed 1px gray;
text-align:center;
position: absolute;
}


.cat-otsikko {
font-weight:bold;
font-size:101%;
}

.cat-hinta {
font-size:108%;
color:#ED1C24;
font-weight:bold;
display:block;
bottom:0px;
position: absolute;
bottom: 0;
}

Update 2

I found Jeaffrey's solution too complicated for me. Can someone provide guidance on how to incorporate user-provided 'mu is too short' code into the following script:

<table border="0" class="tuotteet">
<?php
$productsPerRow = 3;

for($i=0;$i<$count;$i++){
if($i % $productsPerRow == 0) { 
print"<tr>"; 
} 

$tuote = $prods[$i];
print"
<td>
    <span class='cat-otsikko'>".buildLink('prod', $tuote['id'])."</span>
    <div class='product-alaosa'>
        <span class='cat-hinta'>".price($tuote['hinta'])."</span>
        <span class='cat-kori'><a class='button green medium' href='".buildUrl("addtocart", $id)."'>Add to Cart</a></span>
    </div>
</td>
 \n";

 if($i % $productsPerRow == $productsPerRow - 1) { 
 print"</tr>"; 
 } 

}

?>

Answer №1

The CSS vertical positioning model can be quite restrictive, leading you to find workarounds.

Avoid using absolute positioning as it disrupts the document flow and may cause elements to overlap unless you specify exact dimensions for everything.

One solution is to divide a single cell into two cells and apply rowspan="2" to the other cells in the same row:

<tr>
    <td class="top">
        <span class='cat-otsikko'>Product title</span>
    </td>
    <td rowspan="2">
        Short
    </td>
</tr>
<tr>
    <td class="bottom">
        <span class='cat-hinta'>Product price</span>
    </td>
</tr>

You can then use vertical alignment on these table cells:

td.top {
    vertical-align: top;
    border: 1px solid red;
}
td.bottom {
    vertical-align: bottom;
    border: 1px solid green;
}

For a demonstration, check out this link: http://jsfiddle.net/ambiguous/Es6Tn/

This method might not be the most elegant, but it gets the job done. Achieving precise vertical alignment in CSS often involves complicated techniques or resorting to pixel-based positioning.

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

AJAX responses sans the use of jQuery

Similar Question: How can I achieve this through AJAX? After my previous attempt at asking this question, where I was not clear enough, I am making another effort to be as specific as possible. To start with, I have my data encoded using the json_enc ...

Node.js Alternative to HTML5 FileReader: Using 'fs' Module

I attempted to perform file reading and writing operations using JavaScript, but encountered issues with Node.js' 'fs'. After some research, I found that there are equivalent HTML5 APIs available. Is there a comparable method in the HTML5 F ...

Achieving inline display of material-ui components through styling props override

I am struggling to position a checkbox to the right of the "answer input one" field. I've tried adjusting the display property without success. You can see the current layout here. Below is the code for rendering the answer input: <div> ...

Is the width set to fill the entire partial screen?

I'm facing a dilemma: I want the darkest-gray bar at the bottom right (visible after running the code below) to stretch as far as the browser window allows without encroaching on the light-gray section on the left. Here's the code snippet: <d ...

Viewing the html page from a virtual directory seems to be functional in Internet Explorer, but appears to be malfunctioning when accessed

localhost/rupeshwebsite/RJ.htm the URL functions properly in Internet Explorer. I am currently working on a Windows application using C#. The application is being developed as a general one, with scripts provided in a Notepad file for users to place in t ...

photographs showcasing the datepicker widget of jquery-ui

I have implemented the jquery ui datepicker in my project by simply copying and pasting the necessary css and js files. $("#birth_date").datepicker( { changeMonth: true, changeYear: true, yearRange: "1990:2050", dateFormat: 'yy-mm-dd' }) ...

What is the best way to design a collapsed sidebar menu?

I am trying to incorporate a side menu bar into my React application. I want it to be initially closed, only displaying icons, and then expand when clicking on one of the icons. However, I'm facing an issue where the side menu is not closing as intend ...

Ways to showcase an image that goes beyond the top and bottom boundaries of a div using CSS

Attempting to extend an image beyond the top and bottom of a div. Successful in extending it below, but how can I achieve this effect above? Check out the online demo here. .about { background-image: linear-gradient(100deg, #483dec, #4074eb); } .abo ...

Improving the adaptive design of a breadcrumb navigation trail

.breadcrumb input[type="radio"] { display: none; } .breadcrumb input[type="checkbox"] { display: none; } .question-header input[type="radio"] { display: none; } .panel-body input[type="radio"]~label { cursor: pointer; width: 100%; text-align ...

Can someone tell me where I can locate the CSS file once I've finished using Scene Builder?

Currently, I am working on my database project using Scene Builder. I have applied some CSS styling and would like to locate the CSS file in order to attach it to my IntelliJ project for further code editing. Can anyone guide me on where to find the CSS ...

The BG column image is not stretching to full height

I am facing an issue with my website layout where the left column has a background image and another background image is set for the body to fill the rest of the screen. The content area on the right extends vertically beyond the browser window height. How ...

Extracting data from websites and importing it into Excel with VBA

I am venturing into the world of web scraping for the first time using VBA. My goal is to extract pricing information from our company's distributors and save it in an Excel file for our sales team to analyze. The process involves taking the URL from ...

Creating a persistent table header and first column in HTML tables

I am having trouble getting the header column to stick to the top along with the first column beneath it. Here's what I'm aiming for: https://i.stack.imgur.com/hzVt8.png Despite my efforts, I can't seem to make it work. I've experimen ...

Dynamic visual content (map)

I'm currently working on creating an interactive image for my website where clicking on points A, B, C, ... N will reveal bubbles with images and text inside them. Would anyone be able to provide guidance on how to achieve this? Or direct me to resou ...

Creating dynamically adjustable columns in Bootstrap

I've created a simple code for experimentation purposes: <!doctype html> <html lang='en'> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" ty ...

Animate a DIV to the bottom of the page, then with another click, animate it back to the top

I've been working on a div animation where the original position of the div from the top is set at 70% and the div itself is set as absolute. However, when I click on a button, it slides to the bottom of the page with a top value of 95%. Now, my goal ...

Developing a new class within a function

In this section of the HTML file, I have set up a form to collect email and password information from new users in order to create a new profile: <form name="userInfo"> <fieldset> <legend>Create a new account</legend> ...

Is there a way to position the angular loading bar inside a specific 'div' instead of at the top of the page?

Recently, I integrated angular-loading-bar.js into my project to visually represent the progress of http calls. By default, the blue progress bar appears at the top of the screen. However, I wanted to customize it so that it would appear within a specific ...

Issue with VueJS where the datalist input does not reset the value

I am currently working on a Vue component that scans QR codes and adds information to a database upon successful scanning. The scanning process works perfectly fine. However, after successfully sending the data, I need to clear the input field in my datali ...

Changing the color of the timePicker clock in material-ui: a step-by-step guide

I have been attempting to update the color of the time clock in my timeInput component (material-ui-time-picker) for material-ui, but unfortunately, it is not reflecting the change. Here is the code I am using: <TimeInput style ={heure} ...