Positioning text inside HTML table with an image - html

I need to have some text next to an image on an HTML page. So I figured a table was the best way to go...
<table width="500px" >
<tbody>
<tr>
<td align="left">
<p>
<b>Isn't she hot??</b>
</p>
</td>
<td align="right">
<img width="150" height="150" src="http://pixel.nymag.com/imgs/daily/vulture/2015/11/25/25-jennifer-lawrence-directs.w529.h529.jpg" alt="" border="0"/>
</td>
</tr>
</tbody>
Fiddle https://jsfiddle.net/abuMariam/rsnc9vjp/
Problem is what if I want to move that text all the way up or all the way down. I can't because the image width makes both td elements to be wide so I have no way to vertically position the text within its td.
Can I still keep the table but still move the text up and down in its cell?

Yes, just use vertical-align="top" or vertical-align="bottom" on the td. Do you really need to use a table for this though? Tables should seldom be used nowadays, and only for tabular data.
<table width="500px" >
<tbody>
<tr>
<td align="left" style="vertical-align:top;">
<p>
<b>Isn't she hot??</b>
</p>
</td>
<td align="right">
<img width="150" height="150" src="http://pixel.nymag.com/imgs/daily/vulture/2015/11/25/25-jennifer-lawrence-directs.w529.h529.jpg" alt="" border="0"/>
</td>
</tr>
</tbody>
</table>
Here's one way you could do it without using a table, this method causes the divs to act like table cells:
.container {
width:500px;
display:table;
}
.container > div {
width:50%;
display:table-cell;
}
.container > div p {
margin:0;
}
.container .left {
vertical-align:top;
}
.container .right {
text-align:right;
}
<div class="container">
<div class="left">
<p>
<b>Isn't she hot??</b>
</p>
</div>
<div class="right">
<img width="150" height="150" src="http://pixel.nymag.com/imgs/daily/vulture/2015/11/25/25-jennifer-lawrence-directs.w529.h529.jpg" alt="" border="0"/>
</div>
</div>

Related

How can I put content div inside a table

Currently I find myself a table that contains within it a div with a video player, but is moved around on the left side of the screen, I'd like to hit GrindPlayer, how can I do?
<style type="text/css" media="screen">
#GrindPlayer p{
text-align:center;
}
#GrindPlayer{
margin:0 auto;
}
</style>
<table width="100%" border="0" cellspacing="5">
<tr>
<td>
<div id="GrindPlayer">
<p>
Alternative content
</p>
</div>
</td>
</tr>
</table>
and if I can put the full table at the top of the screen. Thank you
If you want the div inside the table at the center, this is the solution.
#GrindPlayer p{
text-align:center;
}
#GrindPlayer{
margin:0 auto;
}
<table width="100%" border="1" cellspacing="5">
<tr>
<td>
<div id="GrindPlayer">
<p>
Alternative content
</p>
</div>
</td>
</tr>
</table>

CSS table styles

CSS is my weak side and now I'm trying to improve it, can you please help me to spot what's the problem is, moreover which css style I'm missing.
<table>
<tr>
<td style=width:"177px; height:92px"><img src="logo.png"></td>
<td rowspan="2"><img src="img2.png"></td>
</tr>
<tr>
<td style=width:"177px; height:100px"><img src="img1.png"></td>
</tr>
</tr>
</table>
UPDATE:
I forgot to mention that I was doing HTML email so solved my issue. Thanks for your help
I think you just need to make the table default CellSpacing and CellPadding 0 (assuming the top picture in your post is the desired result)
<table cellpadding=0 cellspacing=0 >
Although DIV's may be easier
<div>
<div style = width:"177px; height:92px; float:left;">
<img src="logo.png"><br />
<img src="img2.png">
</div>
<div style=width:"177px; height:100px; float:left;">
<img src="img1.png">
</div>
</div>
Then, let's take it 1 step further
<style>
.wrapper
{
background-color:#ccc;
padding:5px;
}
.content
{
width:177px;
height:100px; /*Made them both 100px although one was 92px, this may not be correct*/
float:left;
}
</style>
<div class="wrapper">
<div class="content">
<img src="logo.png"><br />
<img src="img2.png">
</div><!--/content-->
<div class="content">
<img src="img1.png">
</div><!--/content-->
</div><!--/wrapper-->
The property you are looking for may be border-spacing, E.G. border-spacing: 0; (other table specific CSS properties) however you may wish to consult this topic first: Why not use tables for layout in HTML?
Try This one:
css
table {border:1px solid #ccc;
.logo{ width:100px; }.img2{ width:300px }
HTML
<table cellpadding="0" cellspacing="0">
<tr>
<td class="logo">
<img src="logo.png" /><br />
<img src="img1.png">
</td>
<td class="img2"><img src="img2.png"></td>
</tr>
</table>
height is the problem. Decrease the height of logo.png image.

Anchor Tag for Html <TD>

I am coding in html-email. There is a <td> with inline CSS code. What I have to do for attach an anchor tag on whole <td>. Please tell me how can I do it. I have tried many options but these are not valid.
<td valign="top" width="204" class="leftColumnContent" mc:edit="left_column_content" align="center" bgcolor="#dee0e2" style="border-left:6px solid #FFF; border-top:5px solid #FFF;"">
<div align="center" style=" margin-top:10px;">
<img src="" width="119" height="199" style="max-width:180px;" mc:label="image" />
</div>
<p style=" margin-left:20px; width:80%; font-family:Arial, Helvetica, sans-serif; font-size:14px;"> <strong>Text here </strong><br />
<br />
text here</p>
<div style="width:80%; margin-top:10px; margin-left:20px; margin-bottom:15px;">
<div align="left" style="float:left;"><strong> read more</strong></div>
<div align="right">
<img align="none" height="20" id="headerImage2" mc:allowdesigner="" mc:allowtext="" mc:label="header_image" src=".." style="max-width: 55px; width: 55px; height: 23px;" width="55" /></div>
</div>
</td>
You cannot have <a ...><td>...</td></a>, by HTML rules. You can nest them the other way around, <td><a ...>...</a></td>. If you need to make the entire cell clickable, then you need to style the a element so that it occupies the entire cell. The way to do that depends on context, but if the td element has fixed dimensions, then set the following on the a element inside it:
display: block; height: 100%;
you can use the onclick property at the place of Anchor Tag in your table (code).
the Table example is as follows
<table>
<tr>
<td onclick="javascript:alert('your HTML');">HTML Code is here</td>
</tr>
</table>
at the place of alert("") you can use window.location("")
for send the page redirection on another page.

Align two elements to the top and bottom of a table cell

I have a table with multiple rows and columns and each cell contains a link and a few small images. The link needs to be aligned to the top of the cell and the images need to be aligned to the bottom. Unfortunately using the vertical-align attribute doesn't work and both elements are being placed in the middle of the cell. Here is the HTML I have so far:
<table>
<tr>
<td style='width:120px; height:90px;'>
<a href='1.html' style='vertical-align:top'>Link 1</a>
<div style='vertical-align:bottom'><img src='1-1.jpg' /><img src='1-2.jpg' /></div>
</td>
<td style='width:120px; height:90px;'>
<a href='2.html' style='vertical-align:top'>Link 2</a>
<div style='vertical-align:bottom'><img src='2-1.jpg' /><img src='2-2.jpg' /></div>
</td>
</tr>
<tr> ... </tr>
</table>
EDIT: td height and width is also defined at 120 x 90 px
Updated
Referred to http://davidwalsh.name/table-cell-position-absolute and came up with the following answer...
.tlink {
position: relative;
height: 100%;
}
.bimg {
bottom: 0;
position: absolute;
}
<table height="250" border="1">
<tr>
<td>
<div class="tlink">
<a href='#'>Link One</a>
<div class="bimg">
<img src="http://farm4.static.flickr.com/3575/3293166516_de2cd751fc.jpg" width="50" height="50" />
</div>
</div>
</td>
</tr>
</table>

CSS Round Corner on Table Edges Issue in Document Mode IE7 Standards

I got a simple question regarding the CSS background image.
My intention was using image to display round corner on table edges (without using border-radius property).
<style type="text/css">
.top
{
background-repeat:repeat;
vertical-align:top;
}
.left
{
text-align:left;
}
.middle
{
}
.right
{
text-align:right;
}
.bottomLeft
{
vertical-align:bottom;
}
.bottom
{
background-repeat:repeat;
vertical-align:bottom;
}
.bottomRight
{
vertical-align:bottom;
}
</style>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="topLeft">
<img height="16px" src="Images/greenTL.gif" style="vertical-align:bottom" />
</td>
<td class="top">
<img height="4px" width="100%" src="Images/greenT.gif" style="vertical-align:8px" />
</td>
<td class="topRight">
<img height="16px" src="Images/greenTR.gif" style="vertical-align:bottom" />
</td>
</tr>
<tr>
<td class="left">
<img height="100%" src="Images/greenL.gif"/>
</td>
<td class="middle">
</td>
<td class="right">
<img height="100%" src="Images/greenR.gif"/>
</td>
</tr>
<tr>
<td class="bottomLeft">
<img height="16px" src="Images/greenBL.gif" style="vertical-align:top" />
</td>
<td class="bottom" >
<img height="4px" width="100%" src="Images/greenB.gif" />
</td>
<td class="bottomRight">
<img height="16px" width="16px" src="Images/greenBR.gif" style="vertical-align:top"/>
</td>
</tr>
</table>
The HTML & CSS above work perfectly fine in IE from Browser Mode 7 to 9, but it became distorted when changed Document Mode to IE 7 Standard.
It seem like having a gap between left and right vertical.
How can I solve the issue?
Before having CSS3 border-radius, what is the best approach to implement round corner in web page?
thank you in advanced.
I would use something like http://css3pie.com/ which enables some CSS3 features on < IE9
versions. Personally, i'm one of those persons who think that web page shouldn't look 100% the same in all browsers e.g. Chrome/Firefox/Safari should get rounded corners and < IE9 should not.
Don't use tables for layout. For rounded corners in browser that don't support native border-radius, you can use graphics corners as background of absolutely-positioned empty elements.