Vert-Align image and text in same TD in Outlook - css

I am trying to vertical-align an image and a text-element (span) within the same TD.
Heres my code:
<table bgcolor="#ff0000" style="background-color: #ff0000;">
<tbody>
<tr>
<td valign="middle" height="20" style="height: 20px; padding: 5px; vertical-align: middle;">
<a href="#">
<img height="20" width="25" style="display: inline; height: 20px; width: 25px; vertical-align: middle;" src="https://s3-eu-west-1.amazonaws.com/files.crsend.com/181000/181395/images/cart.png"/>
<!--#text_line #-->
<span style="vertical-align: middle; color: #fff;"> 10,95€</span>
<!--#/text_line#-->
</a>
</td>
</tr>
</tbody></table>
Example-Image
I cannot seperate the img-element and the text-element into seperate TD's, because it has to be a single anchor-element wrapping both the image and the text. I cannot wrap the TD's with an anchor-element since it is not HTML-valid and won't work in outlook.
Any Suggestions?
Greetings

Set your table border-collapse to collapse, your td padding to 0 and your anchor display to block. In this way, the anchor element will fit completely your td without useless margins. Then just set vertical-align to middle for both img and anchor element to align them on the same line.
<table style="background-color: #ff0000; border-collapse: collapse;">
<tbody>
<tr>
<td style="padding: 0;">
<a href="#" style="display: block; color: #fff; text-decoration: none; padding: 5px;">
<img src="https://s3-eu-west-1.amazonaws.com/files.crsend.com/181000/181395/images/cart.png" style="height: 20px; width: 25px; vertical-align: middle;" />
<!--#text_line #-->
<span style="vertical-align: middle;"> 10,95€</span>
<!--#/text_line#-->
</a>
</td>
</tr>
</tbody>
</table>

Related

Make image all the same size

.table-img {
height: 50px;
display: block;
margin-left: auto;
margin-right: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<table class="table center-aligned-table table-striped" id="dataTable" cellspacing="0" width="100%">
<thead>
<tr>
<th class="text-center text-primary">Image</th>
<th class="text-center text-primary">Name</th>
<th class="text-center text-primary">Username</th>
<th class="text-center text-primary">Permissions</th>
<th class="text-center text-primary">Status</th>
</tr>
</thead>
<tbody>
<tr class="text-center">
<td><img class="img-responsive img-rounded table-img" src="data:image/png;base64, null"></td>
<td>John Smith</td>
<td>admin</td>
<td>Administrator</td>
<td><label class="badge badge-success">Online</label></td>
</tr>
<tr class="text-center">
<td><img class="img-responsive img-rounded table-img" src="https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/68dd54ca-60cf-4ef7-898b-26d7cbe48ec7/10-dithering-opt.jpg" ></td>
<td>asdajdaslf</td>
<td>admin50</td>
<td>Administrator</td>
<td><label class="badge badge-danger">Offline</label></td>
</tr>
</tbody>
</table>
I'm trying to make my images look like this: http://designcollection.in/codecanyon/table-record/table-design-7.html?ref=designcollection
But so far I've managed to make the images all the same size. The user can input any image size I just want to make the image all the same size and rounded.
https://i.gyazo.com/4eb460be09fea8e0eef939fb9ae4bb0f.png
I'm using bootstrap and I tried this css:
.table-img {
height: 50px;
display: block;
margin-left: auto;
margin-right: auto;
}
Your property height: 50px; is being override by bootstrap's .img-responsive property, giving height: auto;. Either use a higher specificity in your code, or simply load your styles after the bootstrap css, giving the same rules.
To prove my case, change the property to height: 50px !important; and see that is does work. I'm not saying it's a good practice to use !important, it's just a quick way to show you that it's a specificity issue...
Please try snippet code:
.table .table-img {
width: 50px;
height: 50px;
display: block;
margin-left: auto;
margin-right: auto;
border-radius: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<table class="table center-aligned-table table-striped" id="dataTable" cellspacing="0" width="100%">
<thead>
<tr>
<th class="text-center text-primary">Image</th>
<th class="text-center text-primary">Name</th>
<th class="text-center text-primary">Username</th>
<th class="text-center text-primary">Permissions</th>
<th class="text-center text-primary">Status</th>
</tr>
</thead>
<tbody>
<tr class="text-center">
<td><img class="img-responsive img-rounded table-img" src="data:image/png;base64, null"></td>
<td>John Smith</td>
<td>admin</td>
<td>Administrator</td>
<td><label class="badge badge-success">Online</label></td>
</tr>
<tr class="text-center">
<td><img class="img-responsive img-rounded table-img" src="https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/68dd54ca-60cf-4ef7-898b-26d7cbe48ec7/10-dithering-opt.jpg" ></td>
<td>asdajdaslf</td>
<td>admin50</td>
<td>Administrator</td>
<td><label class="badge badge-danger">Offline</label></td>
</tr>
</tbody>
</table>
If maintaining image aspect ratio is important, consider wrapping the img element in a containing element as demonstrated in the embedded code snippet below.
Code Snippet Demonstration:
.table-img {
height: 50px;
width: 50px;
overflow: hidden;
display: block;
margin-left: auto;
margin-right: auto;
border-radius: 100%;
}
.table-img img {
max-height: 50px;
max-width: none;
min-width: 100%;
min-height: 50px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<table class="table center-aligned-table table-striped" id="dataTable" cellspacing="0" width="100%">
<thead>
<tr>
<th class="text-center text-primary">Image</th>
<th class="text-center text-primary">Name</th>
<th class="text-center text-primary">Username</th>
<th class="text-center text-primary">Permissions</th>
<th class="text-center text-primary">Status</th>
</tr>
</thead>
<tbody>
<tr class="text-center">
<td><img class="img-responsive img-rounded table-img" src="data:image/png;base64, null"></td>
<td>John Smith</td>
<td>admin</td>
<td>Administrator</td>
<td><label class="badge badge-success">Online</label></td>
</tr>
<tr class="text-center">
<td>
<div class="table-img"> <!-- new containing element to wrap img -->
<img class="img-responsive img-rounded" src="https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/68dd54ca-60cf-4ef7-898b-26d7cbe48ec7/10-dithering-opt.jpg">
</div>
</td>
<td>asdajdaslf</td>
<td>admin50</td>
<td>Administrator</td>
<td><label class="badge badge-danger">Offline</label></td>
</tr>
</tbody>
</table>
The obvious drawback to this being that landscape orientated images will be better supported than portrait orientated images, but depending on your situation, that may be negligible.
Just add !important to your css:
CSS:
.table-img {
height: 50px !important;
display: block;
margin-left: auto;
margin-right: auto;
}
Because this value is overiden by img-responsive class...
add border-radius: 50%; to make it circular
.table-img {
height: 50px;
display: block;
margin-left: auto;
margin-right: auto;
border-radius: 50%;
}
or
.img-rounded {
border-radius: 50%!important;
height: 30px;
}
style sheet class definition
.table-img {
height: 50px;
width : 50px;
border-radius: 50%;
display: block;
margin-left: auto;
margin-right: auto;
}
then call in html file like this
<table>
<tr><td>
<img class='table-img' src='yourimage.jpg' />
</td></tr>
</table>

Merge bottom border

Has anybody got any idea of how to merge the borders of the 3 elements so that they join together.This is what I currently have:
<div style="float: left; padding-left: 0px; padding-bottom: 2px;">
<table id="table": cellpadding="0" cellspacing="0" border="0">
<tr align="center" valign="middle" >
<td style="padding-left: 1px; padding-right: 0px; padding-bottom: 1px;">
<div id="schedulePrevDay" title="Previous Day" class="borderRad_3Left"> </div>
<asp:TextBox ID="txtDate" runat="server" CssClass="compactDate" MaxLength="10" Width="65px"></asp:TextBox>
<div id="scheduleNextDay" title="Next Day" class="borderRad_3Right"> </div>
</td>
</tr>
</table>
</div>
It seems to me that you're using border-right and border-left 1px solid #fff. So, just remove the border from there:
#schedulePrevDay{
border-right: none;
}
#scheduleNextDay{
border-left: none;
}
Or, you may use negative margin on them.
Maybe a negative margin as Bhojendra Nepal suggested, so it will look something like this
<div style="float: left; padding-left: 0px; padding-bottom: 2px;">
<table id="table": cellpadding="0" cellspacing="0" border="0">
<tr align="center" valign="middle" >
<td style="padding-left: 1px; padding-right: 0px; padding-bottom: 1px;">
<div id="schedulePrevDay" title="Previous Day" class="borderRad_3Left" style="margin-right:-1px;"> </div>
<asp:TextBox ID="txtDate" runat="server" CssClass="compactDate" MaxLength="10" Width="65px"></asp:TextBox>
<div id="scheduleNextDay" title="Next Day" class="borderRad_3Right" style="margin-left:-1px;"> </div>
</td>
</tr>
</table>
Ive used styles but you should also check if there is no padding, margin or borders on these elements before doing a negative margin.

How to replace styled <p> tag in HTML Table for Use in Outlook

How can I achieve the same styling effect you see being used below on the paragraph element for use in Outlook? As you probably know Outlook does not support padding and generally handles the paragraph tag very poorly. Anyway, in Outlook the paragraph element stretches horizontally to both edges of the table. I have successfully used margin-left & margin-right BUT only if I remove the padding!
I believe I need to get rid of the paragraph element all together and just use the table cell as a text container or even create another table within the cell tag but I'm having troubles styling either of those possibilities. I'm going in a bit of a circle here and need the correct solution that will be compatible with all email clients.
<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<table cellspacing="0" cellpadding="0" border="0" height="100%" width="100%">
<tr>
<td align="center" valign="top" style="padding:20px 0 4px 0">
<!-- [ header starts here] -->
<table bgcolor="FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:3px solid #E0E0E0;">
<tr>
<td valign="top" align="center">
<img src="{{var logo_url}}" alt="{{var logo_alt}}" width="351" height="51" /></td>
</tr>
<!-- [ middle starts here] -->
<tr>
<td valign="top">
<p style="border:2px solid #E0E0E0; font-size:12px; line-height:16px; background:#F9F9F9; padding: 16px 18px;"> Welcome, {{htmlescape var=$name}}<br /><br />Please look at {{var product_name}}<br /><br />Here is message: <br />{{var message}}<br /><br /></p>
</td>
</tr>
<tr>
<td bgcolor="#E0E4E6" align="center" style="background:#E0E4E6; text-align:center;"><center><p style="font-size:12px; margin:0; ">Thank you, {{var sender_name}}</p></center></td>
</tr>
<tr><td style="background:ffffff; height="50"; align="center";>
<img src="{{skin url="images/facebook.png" _area='frontend' _package="ljj" _theme="can"}}" height="30" width="34" />
<img src="{{skin url="images/houzz.png" _area='frontend' _package="ljlkj" _theme="can"}}" height="30" width="38" />
<img src="{{skin url="images/instragram.png" _area='frontend' _package="ljlkj" _theme="can"}}" height="30" width="38" />
<img src="{{skin url="images/pinterest.png" _area='frontend' _package="ljlkj" _theme="can"}}" height="30" width="34" /></td></tr>
</table>
</td>
</tr>
</table>
</div>
</body>
body { color:#61777f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
p a {color: #278eb2;}
table {
border-collapse: collapse;
}
You have there two paragraphs, just remove them.
Replace
<td valign="top">
<p style="border:2px solid #E0E0E0; font-size:12px; line-height:16px; background:#F9F9F9; padding: 16px 18px;"> Welcome, ...</p>
</td>
for
<td valign="top" style="border: 2px solid #e0e0e0; font-size: 12px; line-height: 16px; background: #f9f9f9; padding: 16px 18px"> Welcome, ...</td>
And the same with the second one paragraph:
<td bgcolor="#E0E4E6" align="center" style="background:#E0E4E6; text-align:center; font-size:12px; margin:0;">Thank you, {{var sender_name}}</td>
<!-- <center> isn't necessary here, when you used text-align: center; -->
You don't need them in this case.

Aligning radio tag to the image next to it

I want to align my radio tags to the image next to it.
The image is width="260" height="88" and the tag are contained in a table
I tried this but it did not have an affect:
form input[type="radio"]{
vertical-align: middle;
margin-right: 10px;
}
This is the table:
<table border="0" cellpadding="0" align="center">
<tr>
<td height="90">
<input type="radio" value="">
<img src="/images.gif" width="260" height="88" />
</td>
</tr>
</table>
You need to add vertical-align: middle to the image as well. Moreover, since you don't have the <form> tag wrapping the radio button, you only need input[type="radio"] to apply styles to the radio button using CSS.
input[type="radio"] {
vertical-align: middle;
margin-right: 10px;
margin-top: 0px;
}
#image {
vertical-align: middle;
}
<table border="0" cellpadding="0" align="center">
<tr>
<td height="90">
<input type="radio" value="">
<img src="http://placehold.it/350x150" id="image" width="260" height="88" />
</td>
</tr>
</table>

Strange CSS Border Issue in Chrome

I have written an application from which you can write checks and I have the following markup on one of the pages to view and edit some of the fields of the check.
#CheckInformation {
border: 1px solid #aaa;
padding: 10px;
background-color: #E2F0F9;
margin-top: 15px;
}
#CheckInformation #PropertyAddress {
font-size: .87em;
width: 200px;
float: left;
text-align: center;
}
#CheckInformation .label-column {
width: 100px;
}
#CheckInformation .payto-col {
width: 570px;
}
#CheckInformation .line {
border-bottom: 1px solid #aaa;
}
#CheckInformation #PayTo {
width: 540px;
}
#CheckInformation #Address {
width: 200px;
height: 45px;
}
#CheckInformation #Memo {
width: 400px;
}
#CheckInformation #NumberWords {
margin: 3px;
font-style: italic;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css" rel="stylesheet" />
<div id="CheckInformation">
<table>
<tr>
<td class="top" colspan="2" rowspan="2">
<div id="PropertyAddress">
1234 Main St
<br />Some city, State 50000
</div>
</td>
<td class="text-right label-column">Date</td>
<td>
<input type="text"></input>
</td>
</tr>
<tr>
<td class="text-right">Check Number</td>
<td>
<input type="text"></input>
</td>
</tr>
<tr>
<td>Pay to</td>
<td class="payto-col line">
Some person
</td>
<td class="text-right">Amount</td>
<td class="text-right line">
70.00
</td>
</tr>
<tr>
<td></td>
<td class="line" colspan="3">
<div id="NumberWords">Zero Dollars & Zero Cents</div>
</td>
</tr>
<tr>
<td class="top">Address</td>
<td colspan="3">
<div id="Address">
1234 Main St
<br />Some city, State 50000
</div>
</td>
</tr>
<tr>
<td>Memo</td>
<td colspan="3">
<input type="text"></input>
</td>
</tr>
</table>
</div>
It is supposed to have a bottom border on the tds that displays who the check was written to and the amount but not on the labels for those cells. It actually sees to appear correctly in IE and FireFox but in Chrome, I get a bottom border under the Amount label as well.
Running IE 9, FireFox 6.0.2, and Chrome 16.0.912.63
Anyone else see the issue?
Adding table{border-collapse:separate} seems to fix it but I don't know why. I'll update the answer if I figure out more.

Resources