473,414 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Centering an two images concentrically in a <TD> or a <DIV>?

I am trying to center 2 images concentrically which are z-indexed to lay on top of each other making an image with a border from another image that has a transparent center. I need the images to be horizonally and vertically centered within a <TD> </TD> area. No matter what I do the two image just present one above the other, albeit centered, NOT on top of each other.
I originally did the entire page layout in TABLES until I found out I.E. 7 did not handle the image alignment correctly and I have already rewritten much of the page to get my three <td> areas within my main table to be spaced and centered correctly. Since I have now used <div> tags in many places to correct for formating issues with the nested tables I had, I now have basically two vertical menu bars flanking my imaging space in the center; all this is defined by a table and centered in the viewport. I have tried moving the <DIV> outside the <TD> tags, I have tried no <TD> tags which throws the whole page out of wack, I have tried to put the style attribute in the <TD> declaration and a dozen other things. What the heck is going on with this centering?
See my sample code:

Expand|Select|Wrap|Line Numbers
  1. <Table>
  2. <TR>
  3. <TD style="width:75px;height:400px">
  4. Some stuff.
  5. </TD>
  6. <TD style="width:75px;height:400px">
  7. <div style="width:400px;height:400px; text-align:center; vertical-align:middle;">
  8. <img style="z-index:1;" src="photo1.jpg">
  9. <img style="z-index:2;" src="photo2.jpg">
  10. </div>
  11. </TD>
  12. <TD style="width:75px;height:400px">
  13. Some stuff.
  14. </TD>
  15. </TR>
  16. </Table>
Nov 10 '08 #1
4 5257
David Laakso
397 Expert 256MB
Clarification needed: what is the width and the height of each image? Better, yet-- put both images on a public server and point to them with a clickable link to each in your post.
Nov 10 '08 #2
Here is a link to the test code using the coding in my example above:
http://www.digitalphotoonline.com/greetings/cards/test3.html

The individual images are:
http://www.digitalphotoonline.com/greetings/cards/Card_01-h.gif
http://www.digitalphotoonline.com/upload/z/002.jpg
I can resize the 002.jpg image with php code when the time comes.

My first problem is to get the images concentric.
Is there anyway to use the <div> tag as a "position:relative" block and center of that? I guess I could use "position:absolute" but that just kills the flexibility.
In the future I may have multiple opening "overlays" which may require a different approach.
Nov 10 '08 #3
David Laakso
397 Expert 256MB
No tabular data. No table. If this method will work for your situation at hand, no absolute positioning is needed, either. If you want it to render as intended the CSS and markup need to be valid. If you want to cater to the world's most popular browsers -- IE/6 and IE/7 -- the doctype is needed.

Cursory checked in Mac Opera, Safari, Camino, Firefox; and, XP IE/6.0 and IE/7.0.

Please see: some stuff .



HTH.
Nov 10 '08 #4
Thank you for your insight and reply David;
I failed to write in my original post that I had thought about and tried using the background image solution, albeit not nearly as elegantly as your solution. However, there will be a need in the future to be able to position more than one image behind a "mask" as some of the designs will require. I have done some experimenting and found that for some reason "vertical-align:middle" does not work with "positioning:relative" if more than one image is in the <DIV>. So what I have done is simply use a PHP function to resize and calculate the height of the rear image and then for the the second image (the overlay mask) use "position:relative;top:-(height of first image+border height)" this negative "top" adjustment puts the overlay mask in the correct location over the first image. The only issue is that the total <DIV> height is adjusted to the sum of the two image heights as if the two images were one above the other i.e., if both images were 400pixels high, the <DIV> height presents itself as 800 pixels even though the two images are now stacked on top of each other. So stylistically it is not perfect, and if I start putting 3 or 4 images into the <DIV> the height of the area could be unreasonably large, throwing off the stlye of the whole page. If this is the case I will have to go the a PHP GD interface solution that I wanted to avoid just now. If you have any thoughts I would welcome them. Thanks again.
Nov 13 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

61
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will...
1
by: Alan Hoyle | last post by:
I was using a <table border> to generate borders around some info/images, and decided to follow the w3c guidelines and convert it to CSS boxes with borders since it wasn't really tabular data. ...
6
by: Herman Kuiper | last post by:
Hi, The HTML at the end of this message will render erroneously on IE (at least 5.0) and prperly on Mozilla (as I've been told). That does not surprise me, but I *would* like to find some...
3
by: Radek | last post by:
How can I get the following to appear on just 1 line? <style type="text/css"> #center { text-align: center;} #left { text-align: left;} #right {text-align: right} </style> <table border=1...
2
by: listaction | last post by:
Hi Folks, can you help me by explaining how the code below can be translated using <div> and achieve the same effect? Thanks, LA <html> <body> <table bgcolor="#000000" width="100%"...
2
by: js | last post by:
I have a table rendered with XSLT. The first column has a radio button controls for user to make a selection for a particular row. All the values in the remaining columns are all concated with a...
3
by: Josef K. | last post by:
Asp.net generates the following html when producing RadioButton lists: <td><input id="RadioButtonList_3" type="radio" name="MyRadioButtonList" value="644"...
13
by: Mark | last post by:
Dear folks, In Javascript, is it possible to get all id names within, say, a <div></divpair? Like the array of "document.images", I mean. The reason I ask, is that I have a calender whose...
1
by: mark4asp | last post by:
<form runat="server"automatically adds <divtag to code contained within. Is there a way to stop that? Mixing block-level elements with inline-level elements messes up the HTML becasuse that is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.