473,692 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

14 New Member
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 5280
David Laakso
397 Recognized Expert Contributor
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
harryusa
14 New Member
Here is a link to the test code using the coding in my example above:
http://www.digitalphot oonline.com/greetings/cards/test3.html

The individual images are:
http://www.digitalphot oonline.com/greetings/cards/Card_01-h.gif
http://www.digitalphot oonline.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:relat ive" block and center of that? I guess I could use "position:absol ute" 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 Recognized Expert Contributor
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
harryusa
14 New Member
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:re lative" 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:relat ive;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
24476
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 'stretch'</td> <td valign="top" width="300">some data that won't 'stetch'</td> </tr> </table>
1
3904
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. It used to be something like this: <table> <tr> <td><img>caption</td> <td><img>caption</td>
6
3689
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 workaround to get it to display properly... The thing is: on IE5 (Windows) the second "hello" is just not rendered (ok, at least I try to select all text with Ctrl-A...) when the empty <style> element is in the document. If I remove that element, it...
3
3657
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 width=200> <tr>
2
7572
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%" cellspacing="1">
2
11217
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 &#xA0; (blank). I need to retieve the text in each cell of that row if the radio button on that row is clicked. Each <TD> has a numeric ID so that I can use it with document.getElementById().innerText method. I use Javascript to assign some...
3
3807
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" onclick="__doPostBack('SitesRadioButtonList_3','')" language="javascript" />
13
2260
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 <td></tdtable elements, within a given <div></div>, all have a class type, one of which is "today" (to highlight it). Once the calender is drawn, the Javascript has ended. And since Javascript has no known (to me) method of storing variables in say,...
1
2429
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 invalid for a strict implementation. <spanis in-line-level and <divis block-level. I don't want to mix up <span> and <div> I'm using an <asp:Buttonhere because when it switches to the URL I need to check that the user is in the correct role -...
0
8611
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8547
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9090
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8812
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5822
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4329
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2242
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1962
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.