What is the float alternative for the email clients?
Here is what I have using float. And I want the alternative approach to preserve the behavior exactly.
html
<div class="container">
<div class="leftText">
left text
</div>
<div class="rightText">
right text right text
</div>
</div>
css
.leftText {
display: inline-block;
border: 1px solid green;
background: yellow;
}
.rightText {
display: inline-block;
float: right;
border: 1px solid green;
background: cyan;
}
jsfiddle
Here is what I tried to do using available in all email clients text-align and calc (calc is available according to this).
html
<div class="container">
<div class="leftText">
left text
</div>
<div class="rightText">
right text right text
</div>
</div>
css
.leftText {
display: inline-block;
border: 1px solid green;
background: yellow;
}
.rightText {
display: inline-block;
text-align: right;
width: calc(100% - 58px);
min-width: 122px;
border: 1px solid green;
background: cyan;
}
jsfiddle
This approach does not work in a way that when the right text is moved to its own line the words does not wrap due to the min-width being set. If it would be possible to add word wrapping after the right text moved to its own line that solution would be what I seek.
According to this Outlook does not support display: table and after testing it turns out to be true. So, please, do not advise me to use the display: table or similar display (like inline-table, table-row, table-column, table-cell etc.).
float works with nearly every email client except IBM Notes 9, Outlook 2007–16 (desktop PC) and Windows 10.
In email clients where float doesn't work, to float something right, as an example, for a <table> I use either <table align="right"> or <table style="text-align: right;">
Good luck.
As mentioned above, it is possible to use tables to simulate floats. Below is the code using hybrid method of coding. it works the way you want it to.
Note: CSS is just to show you how the stacking would work. Below code can work the same without media queries.
.wrapper{width:680px;outline: 1px solid #f00;}
.wrapper div{outline: 1px solid blue;}
#media screen and (max-width: 480px) {
.wrapper{width:100% !important;}
}
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="wrapper">
<tbody>
<tr>
<td valign="top" bgcolor="#FFFFFF" style="padding:0px;text-align: center; vertical-align: top; font-size: 0px;">
<!--[if (gte mso 9)|(IE)]><table cellspacing="0" cellpadding="0" border="0" width="680" align="center"><tr><td><![endif]-->
<div style="display:inline-block; max-width:340px; min-width:200px; vertical-align:top; width:100%;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="font-size:10px;">left</td>
</tr>
</tbody>
</table>
</div>
<!--[if (gte mso 9)|(IE)]></td><td><![endif]-->
<div style="display:inline-block; max-width:340px; min-width:200px; vertical-align:top; width:100%;">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="font-size:10px;">right</td>
</tr>
</tbody>
</table>
</div>
<!--[if (gte mso 9)|(IE)]></td></tr></table><![endif]-->
</td>
</tr>
</tbody>
</table>
Hope this is the answer you where looking for.
Cheers
Here is the trick I come up with.
html
<div class="l">
left text
</div>
<div class="m">
</div>
<div class="r">
rigth text rigth text
</div>
css
.l {
display: inline-block;
}
.m {
display: inline-block;
width: calc(100% - 180px);
}
.r {
display: inline-block;
}
jsfiddle.
It is straightforward. I need to always have a distance between left and right component as much as possible and it is depicted in the calc property of the fictitious element.
Related
I'm trying to align two DIVs in a Table TD to the bottom of that table, but for some reason the DIV on the left is refusing to budge. I have tried various alignment methods etc but it will not move to the bottom. The email I am designing is meant to be responsive so I have to ensure that when the window is narrowed, it still works.
JSFiddle here:
http://jsfiddle.net/hirenshah/rdux8vkg/
HTML:
<body bgcolor="#C0C0C0">
<!--[if (gte mso 9)|(IE)]>
<table width="600" align="center" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<![endif]-->
<table class="container" width="300px" cellpadding="0" cellspacing="0" style="max-width: 600px; background-color: white; margin-left: auto; margin-right: auto;">
<tr>
<td>
<!-- Header Table Start -->
<table width="100%" cellpadding="0" cellspacing="0" >
<tr>
<td style="text-align: center; vertical-align:bottom; font-size: 0;">
<div class="headercolumnright">
<img src="http://hirenshah.co.uk/poc/logo.png" width="50%"/></div>
<div class="headercolumnleft ">Reference: 123456789</div>
</td>
</tr>
</table>
<!-- Header Table End -->
</td>
</tr>
</table>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</body>
CSS:
#media screen and (min-width: 601px) {
.container {
width:600px !important;
}
.headercolumnright {
text-align:right !important;
}
}
.headercolumnleft {
width: 300px;
display: inline-block;
text-align:left;
float: left;
font-size:12pt;
}
.headercolumnright {
width: 300px;
display: inline-block;
text-align:left;
float: right;
font-size:12pt;
vertical-align:bottom;
}
div {
outline: 1px solid red;
}
Try putting the Left DIV before the RIGHT div and that should fix it...
<tr>
<td style="text-align: center; vertical-align:bottom; font-size: 0;">
<div class="headercolumnleft ">Reference: 123456789</div>
<div class="headercolumnright">
<img src="http://hirenshah.co.uk/poc/logo.png" width="50%"/></div>
</td>
</tr>
I tried it in your JSFiddle and it worked fine.
Cliff.
I have a small problem I cannot get solved.
Please take a look at my html and my css. Why are the pictures perfectly responsive in safari,firefox,chrome but aren't in IE 8 through 10?
html:
<table class="my-table">
<tbody>
<tr>
<td height="130"><img style="display: block; margin-left: auto; margin-right: auto;" src="/images/sponsoren/kuratli.gif" alt="Kuratli Collection" width="100%" height="auto" /> </td>
<td height="130"><img style="display: block; margin-left: auto; margin-right: auto;" src="/images/sponsoren/Logo_Migros.JPG" alt="Migros" width="100%" height="auto" /> </td>
<td height="130"><img style="display: block; margin-left: auto; margin-right: auto;" src="/images/sponsoren/Logo_Webergartenbau.gif" alt="Webergartenbau" width="100%" height="auto" /> </td>
</tr>
</tbody>
</table>
css:
table.my-table td {
width: 33% !important;
border: 1px solid #dddddd !important;
}
table.my-table {
width: 100% !important;
table-layout: fixed !important;
border-spacing: 0.5rem !important;
border-collapse: separate !important;
}
I am pretty new to both, html and css. I'd like to keep the table since it gives me a nice layout, but I am open for everything which solves my problem.
Can someone help me?
Apparently height="auto" is implemented differently in different browsers. Something that can't by relied upon.
If you remove that, though, images might exceed the space meant for them.
Try omitting the height attribute, and adding to the css:
table.my-table td img{
max-height: 100%;
}
Here is the html code that makes the table:
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<div class="profile">
<img src="http://www.teleread.com/wpcontent/uploads/2009/05/image18.png" />
</div>
</td>
<td>Hello</td>
</tr>
</table>
Here is the css:
.profile img {
width: 120px;
height: 125px;
float: left;
margin-right: 4px;
margin-top: 4px;
margin-bottom: 4px;
border: 1px #cc1212 solid;
clear: both;
}
Here is the code in action on jsfiddle:
http://jsfiddle.net/Yeqnn/
THE ISSUE: The word "Hello" is vertically centered in the right column
How do I fix this? BTW, the image has to be in the table and floated left to work with my current theme... any ideas, if so drop an answer plz.
Simply put vertical-align: top; on your <td> elements.
Demo
I've been trying to align an image to the center of the table td. It worked with setting margin-left to a specific value but it also increased the size of td too and that isn't exactly what I wanted
Is there any efficient ways of doing this? I used percentages for the height and witdh of the table.
<td align="center">
or via css, which is the preferred method any more...
<td style="text-align: center;">
Simple way to do it for html5 in css:
td img{
display: block;
margin-left: auto;
margin-right: auto;
}
Worked for me perfectly.
Center a div inside td using margin, the trick is to make the div width the same as the image width.
<td>
<div style="margin: 0 auto; width: 130px">
<img src="me.jpg" alt="me" style="width: 130px" />
</div>
</td>
This fixed issues for me:
<style>
.super-centered {
position:absolute;
width:100%;
height:100%;
text-align:center;
vertical-align:middle;
z-index: 9999;
}
</style>
<table class="super-centered"><tr><td style="width:100%;height:100%;" align="center" valign="middle" >
<img alt="Loading ..." src="/ALHTheme/themes/html/ALHTheme/images/loading.gif">
</td></tr></table>
Set a fixed with of your image in your css and add an auto-margin/padding on the image to...
div.image img {
width: 100px;
margin: auto;
}
Or set the text-align to center...
td {
text-align: center;
}
<table style="width:100%;">
<tbody ><tr><td align="center">
<img src="axe.JPG" />
</td>
</tr>
</tbody>
</table>
or
td
{
text-align:center;
}
in the CSS file
td image
{
display: block;
margin-left: auto;
margin-right: auto;
}
Another option is the use <th> instead of <td>. <th> defaults to center; <td> defaults to left.
As per my analysis and search on the internet also, I could not found a way to centre the image vertically centred using <div> it was possible only using <table> because table provides the following property:
valign="middle"
I want to keep the tables but use css to achieve the same positioning result with a strict doctype. This is the design that does exactly what I need.
Notice the <br> tags in the last (bottom) <td> cell. As this area grows, the position of the data within two other <td> cells above it do not change position.
<table cellpadding="0" cellspacing="0" border="1" width="400" height="100%">
<tr>
<td valign="top">
<table cellpadding="0" cellspacing="0" border="0" height="100%">
<tr>
<td valign="top">ds</td> <----- The position here is important
</tr>
<tr>
<td valign="bottom">ds</td> <----- The position here is important
</tr>
</table>
</td>
<td valign="top">ada adf ad<br><br><br><br><br><br><br><br><br></td>
</tr>
</table>
I made an example for you here to show you how easy it is to duplicate that table with Divs and CSS:
HTML:
<div id="main-div-wrap">
<div class="left-content">
<span class="top">ds</span>
<span class="bottom">ds</span>
</div>
<div class="right-content">
ada adf ad
</div>
</div>
CSS:
#main-div-wrap
{
position: absolute;
width: 400px;
height: 200px;
border: 1px solid #000;
}
.left-content
{
width: 18%;
float: left;
height: 100%;
}
.right-content
{
margin-left; 18%;
width: auto;
float: left;
height: 100%;
border-left: 1px solid #000;
}
.top
{
position: absolute;
display: block;
top: 0;
}
.bottom
{
position: absolute;
display: block;
bottom: 0;
}
All semantic, no hacks, will validate and if you need to change it for browsers, theres more than enough tools out there to help you.
I'm not sure what you mean with "keep the tables for the structure", but I guess you what something like this, however if the content is too short, then the "top" and "bottom" texts will overlap.
http://jsfiddle.net/HsmKA/
Variant with CSS styled tables:
http://jsfiddle.net/JmQ55/
You can find all you want here.
Coming from a tables word myself I've always found the DIV layout a pain in the a$$.
Check out blue print css its a very easy to use CSS framework. Might sort you out