How to set a table at the bottom of a div - html

I need my table to align at the bottom of my div, I've tried adding to the table's style the attributes : position:absolute;bottom:0px but it changed according to the page and not the div. I posted the full code (with img tag) cus i'm not sure about the influence of other tags.
//HTML
<div>
<img src="Img/flower" style="width: 960px; height: 474px; z-index: -1; position: absolute" />
<table style="width:100%;height:120px;">
<tr>
<td style="background-color:gray">
</td>
<td style="background-color:green">
</td>
<td style="background-color:yellow">
</td>
<td style="background-color:red">
</td>
<td style="background-color:lime">
</td>
<td style="background-color:maroon">
</td>
</tr>
</table></div>

Your parent "div" and "img" should be declared as "position:relative" in this
case.
here is your solution:
<div style="position: relative;">
<img src="Img/flower" style="width: 960px; height: 474px; z-index: -1; position: relative;">
<table style="width: 100%; height: 120px;">
<tbody><tr>
<td style="background-color:gray">
</td>
<td style="background-color:green">
</td>
<td style="background-color:yellow">
</td>
<td style="background-color:red">
</td>
<td style="background-color:lime">
</td>
<td style="background-color:maroon">
</td>
</tr>
</tbody></table>
</div>

You can also use CSS Flexbox (check browser support) to vertical align:
https://philipwalton.github.io/solved-by-flexbox/demos/vertical-centering/
<div class="Aligner">
<div class="Aligner-item Aligner-item--bottom">…</div>
</div>
<style>
.Aligner {
display: flex;
align-items: center;
justify-content: center;
}
.Aligner-item--bottom {
align-self: flex-end;
}
<style>

Related

Hot to make multiple element both on the left side and right side on html email?

It should support for html email, so I can't use justify-content and align-items.
I try to use position: absolute for <img />, but It's not working on html email ?
Hot do I make the Twitter icon on the left side and on the same line with 1 2 3 for html email ?
<div
class="footer-container"
style="
position: relative;
background: pink;
position: fixed;
bottom: 0;
width: 100%;"
>
<!-- position is not working on html email -->
<div
class="image-container"
style="position: absolute; top: 30px; left: 24px"
>
<img
src="https://www.citypng.com/public/uploads/preview/-516139511470ymv2hndq6.png"
alt="test"
width="94"
/>
</div>
<div
class="centered"
style="padding-top: 40px; padding-bottom: 40px; padding-right: 30px; text-align:right;"
>
<a>1</a>
<a>2</a>
<a>3</a>
</div>
</div>
In email-templates you have limited support and as such sue techniques that are outdated or would not be semantically correct for normal HTML files.
In this case, you should use a table for layout purposes. You can shrink the table cells to their minimum content by using: style="width: 0; white-space: nowrap;"
<table width="100%">
<tr>
<td>
<img src="https://www.citypng.com/public/uploads/preview/-516139511470ymv2hndq6.png" alt="test" width="94">
</td>
<td style="width: 0; white-space: nowrap;">
<a>1</a>
</td>
<td style="width: 0; white-space: nowrap;">
<a>2</a>
</td>
<td style="width: 0; white-space: nowrap;">
<a>3</a>
</td>
</tr>
</table>
People forget that HTML email Table can be treated as a "grid" layout by using colspan (and rowspan as well). Usually a grid of 6 columns fits best for most of the cases. Knowing you have such a grid, the top row can be constructed as such colspans, and by using text-align:
<style>
td {
border: 1px solid #ddd;
padding: 1rem;
}
</style>
<table cellspacing="0" cellpadding="0" border="0" style="width: 100%; table-layout: fixed; border-collapse: collapse; border: 0px;border-spacing: 0;">
<tbody>
<tr>
<td colspan="2">
<img src="https://i.stack.imgur.com/q9TPY.png" alt="logo" style="display: block; vertical-align: middle; border: 0;" width="57" height="48">
</td>
<td colspan="4" style="text-align: right;">
Link 1
Link 2
Link 3
</td>
</tr>
<tr>
<td colspan="6" style="text-align: center; background: gold;"><br><br>6<br><br><br></td>
</tr>
<tr>
<td colspan="3">3</td>
<td colspan="3">3</td>
</tr>
<tr>
<td colspan="2">2</td>
<td colspan="2">2</td>
<td colspan="2">2</td>
</tr>
<tr>
<td colspan="5" style="text-align: center; background: #567; color:#fff;">5</td>
<td colspan="1" style="text-align: center; background: #456; color:#fff;">1</td>
</tr>
</tbody>
</table>

td width not apply when table wrapped with div with specific width and overflow is applied

With the below html, I am not able to add width of td element
here table is wrapped with div and it's width is 200px and overflow-x is given.
<div class="scroll" style="width: 200px; overflow-x: overlay;">
<table class="scrollable">
<tbody>
<tr>
<td width="100" data-index="0" style="width: 118px;">-0.29%</td>
<td data-index="1">-0.26%</td>
<td data-index="2">-0.20%</td><td data-index="3">-0.15%</td>
<td data-index="4">-0.09%</td><td data-index="5">0.19%</td>
<td data-index="6">0.54%</td><td data-index="7">0.95%</td>
<td data-index="8">1.33%</td><td data-index="9">1.67%</td>
<td data-index="10">1.97%</td><td data-index="11">2.22%</td>
<td data-index="12">2.44%</td><td data-index="13">2.62%</td>
<td data-index="14">2.78%</td>
</tr>
</tbody>
</table>
</div>
Try changing the display property of <td> to display:inline-block.
Also you should add this table { width: max-content; } to your CSS so your table can fit all the <td> now that they are bigger.
table {
width: max-content;
}
td {
width: 100px;
display: inline-block;
}
<div class="scroll" style="
width: 200px;
overflow-x: auto;
">
<table class="scrollable">
<tbody>
<tr>
<td data-index="0">-0.29%</td>
<td data-index="1">-0.26%</td>
<td data-index="2">-0.20%</td>
<td data-index="3">-0.15%</td>
<td data-index="4">-0.09%</td>
<td data-index="5">0.19%</td>
<td data-index="6">0.54%</td>
<td data-index="7">0.95%</td>
<td data-index="8">1.33%</td>
<td data-index="9">1.67%</td>
<td data-index="10">1.97%</td>
<td data-index="11">2.22%</td>
<td data-index="12">2.44%</td>
<td data-index="13">2.62%</td>
<td data-index="14">2.78%</td>
</tr>
</tbody>
</table>
</div>

How to align image to right on FreeMarker

I'm trying to align the last image on the right side of the page in order to make it looks like simmetric
The code I'm using on FTL is the following but it is always next to the middle section:
<table class="header">
<tr>
<td align="left" valign="middle">
<img src="${logo1}" style="float: left; margin: 7px; width: 120px; height: 67.5px" />
</td>
<td align="left" valign="middle" style=" margin-left: 50px;">
<span class="infos" style="font-size:17pt"><b>${info}</b></span><br/>
</td>
<td align="right" valign="right">
<img src="${lastLogo}" style="float: right; margin: 7px; width: 120px; height: 67.5px" />
</td>
</tr>
</table>
If you make your table take up 100% width, it will do as you desire.
<table class="header" style="width: 100%">
<tr>
<td align="left" valign="middle">
<img src="${logo1}" style="float: left; margin: 7px; width: 120px; height: 67.5px" />
</td>
<td align="left" valign="middle" style=" margin-left: 50px;">
<span class="infos" style="font-size:17pt"><b>${info}</b></span><br/>
</td>
<td align="right" valign="middle">
<img src="${lastLogo}" style="float: right; margin: 7px; width: 120px; height: 67.5px" />
</td>
</tr>
</table>
An example below, but don't use styly inline that way.
We currently use tables for tabular data, otherwise we create everything on div.
*,
:after,
:before {
box-sizing: border-box;
}
<table class="header">
<tr>
<td>
<img src="https://fakeimg.pl/120x60/ff0000/fff" style="width: 120px;" />
</td>
<td>
<div class="infos" style="border: 1px solid red; padding: 0 20px; font-size:17px; max-width: 120px;">
<b>Lorem ipsum dolor sit.</b>
</div>
</td>
<td>
<img src="https://fakeimg.pl/120x60/4efc03/000" style="width: 120px;" />
</td>
</tr>
</table>
Better solution
*,
:after,
:before {
box-sizing: border-box;
}
.header {
display: flex;
justify-content: space-between;
}
.header img {
width: 120px;
}
.infos {
display: flex;
align-items: center;
}
<div class="header">
<div><img src="https://fakeimg.pl/120x60/ff0000/fff"></div>
<div class="infos">
<b>Lorem ipsum dolor sit.</b>
</div>
<div><img src="https://fakeimg.pl/120x60/4efc03/000"></div>
</div>

Alignment Issue with Table Structure

Here is the code for aligning contact details:
<html>
<body>
<table width="900" class="contact-details">
<tr>
<td><img src="./images/Mobile.png"></td>
<td>
<p>832.674.6834</p>
</td>
<td><img src="./images/fax.png"></td>
<td>
<p>271.217.4981</p>
</td>
<td><img src="./images/email.png"></td>
<td>
<p>test#testpineced.com</p>
</td>
<td><img src="./images/address.png"></td>
<td>
<p>1055 Loremips Tr. Kity, TX</p>
</td>
</tr>
</table>
<style>
img {
/* width: 100%; */
display: block;
}
</style>
</body>
</html>
You can see there is gap difference in between images and text content. Can you please help me to make equal gap difference and fit full content inside the table class.
Please see the screenshot attached: https://imgur.com/a/tjd9UOo
use css class for td and for each td can specify the inline width & height
.img {
background-repeat:no-repeat;
background-size: cover;
}
<table width="900" class="contact-details">
<tr>
<td style="background-image:url(./images/Mobile.png); width: 50px; height: 80px;"> </td>
<td><p>832.674.6834</p></td>
<td class="img" style="background-image:url(./images/fax.png); width: 50px; height: 80px;"> </td>
<td><p>271.217.4981</p></td>
<td class="img" style="background-image:url(./images/email.png); width: 50px; height: 80px;"> </td>
<td><p>test#testpineced.com</p></td>
<td class="img" style="background-image:url(./images/address.png); width: 50px; height: 80px;"> </td>
<td><p>1055 Loremips Tr. Kity, TX</p></td>
</tr>
</table>
<table width="900" class="contact-details" >
<tr>
<td style='width: 30px'><img style='width: 30px' src="./images/Mobile.png"></td>
<td>832.674.6834</td>
<td style='width: 30px'><img style='width: 30px' src="./images/fax.png"></td>
<td>271.217.4981</td>
<td style='width: 30px'><img style='width: 30px' src="./images/email.png"></td>
<td>test#testpineced.com</td>
<td style='width: 30px'><img style='width: 30px' src="./images/address.png"></td>
<td>1055 Loremips Tr. Kity, TX</td>
</tr>
just change the width px according to the image width
**You have to remove width="900" and add padding to <td> element**
<html>
<head>
<style>
img {
/* width: 100%; */
display: block;
}
table{
margin:0 auto;
}
td{
padding-top:5%;
padding-left: 1%;
}
</style>
</head>
<body>
<table class="contact-details">
<tr>
<td><img src="./images/Mobile.png"></td>
<td>
<p>832.674.6834</p>
</td>
<td><img src="./images/fax.png"></td>
<td>
<p>271.217.4981</p>
</td>
<td><img src="./images/email.png"></td>
<td>
<p>test#testpineced.com</p>
</td>
<td><img src="./images/address.png"></td>
<td>
<p>1055 Loremips Tr. Kity, TX</p>
</td>
</tr>
</table>
</body>
</html>

horizantal scroll of div is not working

The vertical scroll works, but the horizontal doesn't. My code:
<html >
<body >
<table style=" height:100%; width:100%">
<tr>
<td >
<div style=" overflow:scroll; height:100%; width:100%">
<table style=" width:2000px; height:2000px; ">
<tr><td></td></tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>
Table is not an ideal element to use unless u want to display a table/table of contents.
Always prefer divs than tables.
This should do inside ur <body>
<div style="height: 100%; width: 100%">
<div style="overflow: scroll; height: 100%; width: 100%">
<table style="width: 2000px; height: 2000px;">
<tr>
<td>
</td>
</tr>
</table>
</div>
With Table u will have to set table-layout:fixed ,
<table style="height: 100%; width: 100%; table-layout:fixed">
<tr>
<td>
<div style="overflow: scroll; height: 100%; width: 100%">
<table style="width: 2000px; height: 2000px;">
<tr>
<td style="width:50%; display:none">
</td>
<td style="width:50%; display:none">
</td>
</tr>
<tr>
<td>control here will auto-align to 50%</td>
<td>control here will auto-align to 50%</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
I have modified the td template. Please note that as well.
i changed your code like this
<html >
<body >
<table style=" height:100%; width:100%">
<tr>
<td >
<div style=" overflow:scroll; height:2000px; width:100%">
<table style=" width:2000px; height:2000px; overflow:scroll;">
<tr><td></td></tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>
try this.it will work..