Forum Moderators: not2easy
An image with three captions, by default visibility:hidden; An imagemap is attached and Scripting to set the caption's visibility:visible when the mouse moves over a certain area. Kind of "popup-captions" :-)
The problem:
The captions should appear close to that mapped onmouseover-area, but I don't know how to position them. position:absolute (which is what I am using right now) works on the whole page, but them image could be -floatingwise- anywhere. position:relative doesn't allow me to display the images on top of the main document layer.
Has anybody worked on something similar? I guess I'm looking for "a way to depend the captions' positions on the image's position without them being inline"...
It comes to down to finding a way to place several divisions at the same left:/top: position as a document-inline (not position:absolute) image is.
These division should not render into the body but float ontop (I tried z-index without success). This way I could place captions (they could appear right next the image detail they belong to) and/or parts of the image (for example as a rollover using an imagemap) anywhere I want. Does that make any sense?
#theimg {
float: left;
}
#caption1, #caption2, #caption3 {
display: none;
float: left;
margin-left: -250px;
width: 250px;
height: 100px;
}
<div>
<img id="theimg" width="250" height="100">
<div id="caption1">Caption 1</div>
<div id="caption2">Caption 2</div>
<div id="caption3">Caption 3</div>
</div>
Now, use JavaScript to toggle the display property: none vs. block
How do I get to move them to a desired position now?
Using this technique for captions only I can simply position the text with Paddings.
It would be *brilliant* now to attach a background-image that works as the rollover. But modifying Left: and Top: doesn't have any effect...
<added:>I inserted "position:relative;" to the #captions and it's starting to work...</added
The current status:
It looks like using floats for the image and the captions, and forcing the captions' margins to (negative) match the width of the image, places them right on top - this is done without z-index'ing (anybody expierenced with z-index?).
<div class="imagebox">
<img id="mainimage" src="xxx.jpg" width="400" height="250" alt="xxx" usemap="#imagemap" onmouseout="document.getElementById('caption1').style.display='none'; document.getElementById('caption2').style.display='none'; document.getElementById('caption3').style.display='none';">
<p id="caption1" style="left:0px; top:0px;">xxx</p>
<p id="caption2" style="left:0px; top:0px;">xxx</p>
<p id="caption3" style="left:0px; top:0px;">xxx</p>
</div>
Ok, we wrap the whole image plus captions into an 'imagebox' that contains some cosmetics...
.imagebox{ width: 400px; height:250px; float:right; margin-left:30px; }
The #mainimage's width and height are defined, and (very important) it's set to float left;
#mainimage{ float: left; width: 400px; height:250px; }
The three captions are also set to float left; margin-left is set to the image's width. Now their left/top position *should* equal the image. The rest is mostly cosmetics:
#caption1, #caption2, #caption3 {
display: none;
float: left;
margin: 0px;
margin-left: -400px;
width:200px;
text-align:justify;
text-indent:0px;
font-weight:bold; color:#000000; padding:8px; font-size:0.8em;
position: relative;
background-color: #FFFFFF;
border: 1px solid #000000;
}
I chose a fixed width so the captions get some sort of "shape". The actual left/top positioning I kept in the html document (style="") for the time being - since it depends on the individual html pages' image's details.
To include a "rollover" effect one just adds
background-image: url(images/rollover-effect-1/2/3.gif);
to that inline style while the image can contain anything from highlighted parts of the image to marking (transparent) circles or rectangles.
Now just place a client side image map on top of that image:
<map name="imagemap" id="imagemap">
<area alt="" coords="370,38,402,121" onmouseover="javascript: document.getElementById('caption1').style.display='block'; document.getElementById('caption2').style.display='none'; document.getElementById('caption3').style.display='none';">
<area alt="" coords="321,36,363,123" onmouseover="javascript: document.getElementById('caption1').style.display='none'; document.getElementById('caption2').style.display='block'; document.getElementById('caption3').style.display='none';">
<area alt="" coords="244,32,313,125" onmouseover="javascript: document.getElementById('caption1').style.display='none'; document.getElementById('caption2').style.display='none'; document.getElementById('caption3').style.display='block';">
</map>
Well this all works fine in theory; I got one problem though:
While Netscape renders fine; IE 6 will not place "some" captions to the given left:/top: attributes, but instead seems to take other objects into rendering account.