Web Design Forum: Centering images 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 images in table. Using text-align:center on divs to centre/center images.

#1 User is offline   Funkybass99 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 13
  • Joined: 09-November 11
  • Reputation: 0

Posted 08 February 2012 - 11:24 AM

Hi, I set up some images to 'text-align:center;' by putting each image in a div and aligning each of the divs by applying a style to each div seperately. It all seemed to be working fine when I looked at it in IE8. However, now I'm doing some work at home, I have viewed it in later browsers and it doesn't seem to be working at all. I have tried applying css to each table row too, but to no avail. Any idea how I can remedy this please? I have pasted the appropriate scripts below. Thanks.

HTML:

<h2>Who Are We?</h2>
<p>&nbsp;</p>
<table width="681" border="5" bordercolor="#00596B" >
<tr class="tbrow_center_image">
<td width="216" height="176"> <div class="centered_image"> <img src="../images/staff_photos/staff_photo_06.jpg" alt="image description" width="156" height="200"> </div> </td>
<td width="220"><div class="centered_image"> <img src="../images/staff_photos/staff_photo_04.jpg" alt="image description" width="156" height="200"> </div></td>
<td width="223"><div class="centered_image"> <img src="../images/staff_photos/staff_photo_02.jpg" alt="image description" width="156" height="200"> </div></td>
</tr>
</table>


CSS in seperate file:


.centered_image
{
text-align:center;
margin-top:0px;
margin-bottom:0px;
padding:0px;
width:156px;
}

.tbrow_center_image
{
text-align:center;
}
0

#2 User is online   MikeChipshop 

  • Small but imperfectly formed
  • Group: Moderators
  • Posts: 7,047
  • Joined: 19-April 10
  • Reputation: 503
  • Gender:Male
  • Location:Scotland

Posted 08 February 2012 - 11:25 AM

Is there a need for the table? Is the data tabular?

If not then you'd be far better off dropping the table completely and using a normal fluid DIV layout.
0

#3 User is offline   Funkybass99 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 13
  • Joined: 09-November 11
  • Reputation: 0

Posted 08 February 2012 - 01:38 PM

Yes, I suppose it is tabular, I haven't put the whole table contents there, I just copied the first row.
0

#4 User is offline   sash_oo7 

  • Forum Newcomer
  • PipPipPipPip
  • Group: Members
  • Posts: 838
  • Joined: 15-August 10
  • Reputation: 45
  • Gender:Male
  • Location:Mars
  • Experience:Nothing
  • Area of Expertise:Nothing

Posted 08 February 2012 - 02:07 PM

have u tried adding class to the image and adjust margin? if all images are of same dimension? or adjust padding of the containing td by adding a class?
0

#5 User is offline   porkchops 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,073
  • Joined: 13-March 11
  • Reputation: 228
  • Gender:Male
  • Location:Belmont, Massachusetts
  • Experience:Advanced
  • Area of Expertise:Web Designer

Posted 08 February 2012 - 02:19 PM

If you put text align center on the TD with the image it should work, and you can also put margin: 0 auto; on the images, but not sure how that behaves in a table.

However, unless this has multiple (3 or more) columns and is information that belongs in a table in a book you probably would be better off by using CSS. If you have to nest another block-level element inside a table cell you probably aren't using tables semantically.

This post has been edited by porkchops: 08 February 2012 - 02:20 PM

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