Web Design Forum: Centering image in table - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Centering image in table Seems to want to align left

#1 User is offline   Str8TalkingBob 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 14
  • Joined: 02-January 10
  • Reputation: 0

Posted 02 January 2010 - 06:33 PM

Hi all i'm having a problem with a table i've created with 3 images in. I am trying to get the 1st image aligning left, the 2nd centered and the third to the right. It's ok apart from the centered image is aligning to the left for some reason. The code i'm using for the table is:

<table border="0" width="100%" cellpadding="0">
<tr>
<td width="33.3%" valign="top">
<img class="logo" src="image/logo.png"; align="left"; width="287"; height="145">
</td>
<td width="33.3%" valign="top">
<img class="logo2" src="image/logo.png"; align="center"; width="287"; height="145">
</td>
<td width="33.3%" valign="top">
<img class="logo3" src="image/logo.png"; align="right"; width="287"; height="145">
</td>
</tr>
</table>


And the corresponding CSS in my linked CSS file is:

img.logo {border:1px solid green; float: left;}
img.logo2 {border:1px solid green; position:center;}
img.logo3 {border:1px solid green; position:absolute-right;}


I've tried removing the class from the image so it relates to nothing in the css file but it still aligns to the left.

Does anyone have any idea what is going on? :)
0

#2 User is offline   Wickham 

  • Web Guru
  • View gallery
  • Group: Moderators
  • Posts: 2,875
  • Joined: 11-June 09
  • Reputation: 257
  • Gender:Male
  • Location:Salisbury UK
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 02 January 2010 - 08:48 PM

You're going to have trouble getting it to look right in all window resolutions. Your table is 100% wide and each td tag is 33.3% wide, and images are 287px wide, so what will happen in a window width of 600px where the td width is 200px? The table cells will expand as necessary to 287px and the table will project to the right.

Your css doesn't look good either. If the window is say 1200px wide and each td tag is 400px wide, then this css should put the first image on the left of the first td tag, the second should center in the center td tag and the last should be on the right of the last td tag (you don't need float or position if you edit the align="..." into the td tag in the body markup):-

img.logo {border:1px solid green; }
img.logo2 {border:1px solid green;}
img.logo3 {border:1px solid green;}


Your align=".." codes should be in the td tags:-

<table border="0" width="100%" cellpadding="0">
<tr>
<td width="33.3%" valign="top" align="left";>
<img class="logo" src="image/logo.png"; width="287"; height="145">
</td>
<td width="33.3%" valign="top" align="center";>
<img class="logo2" src="image/logo.png"; width="287"; height="145">
</td>
<td width="33.3%" valign="top" align="right";>
<img class="logo3" src="image/logo.png"; width="287"; height="145">
</td>
</tr>
</table>


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users