Forum Moderators: open
Is there a way to do this ( Im targetting mozilla, so not working in IE is ok )?
You could use absolute positioning.
img.something
{ position: absolute;
top: 100px;
left: 100px;
width: 64px;
height: 64px;
}
Of course you could use whatever combination of top, right, bottom or left to place your images however you see fit.
You could use percentages as well.
M
[edited by: madcat at 4:34 pm (utc) on Aug. 27, 2002]
eg: One image is 42x64 ( and displays perfectly ),
the next image is 64x43,
and a third is 64x50
All three have the top of the image aligned with the top of its respective div, and it looks pretty bad.
At this point Ive resorted to wrapping each image in a table, which can do crazy things like dynamic vertical sizing.
So far Im quite dissappointed with how weak divs are, in comparison to tables.
After playing with this a lot, Ive worked out that the vertical center is only ever in the context of surrounding text. Hence even putting it in a <p> doesnt help, because it is only centered relative to text within the <p>. The <p> itself will not center relative to the div.
I will try the auto margin thing, Ive never seen that before.
What Im creating is a photo album, that is dynamically generated from the contents of a directory. You can have a look if you want: <edit - sorry, no personal URLs>
navigate into the photo ablum and then into beach, or deep into the new zealand album.
One solution would be to put transparent borders on the thumbnails so that they are all 64x64, but that is a bit difficult for my intended users, who are just going to be scanning images and uploading them to the albums.
[edited by: tedster at 2:44 am (utc) on Aug. 29, 2002]
I played around with the problem quite a lot too, my solution is a little JS+DOM-script to center them.
Images to be centered must have the attribute id="centered1", centered2, centered3 and so on to infinity. The script must be at the end of the document.
Demo page link in my profile.
<script language="JavaScript" type="text/javascript">
function centerit(which, i) {
var which2 = which+i;
if (document.getElementById(which2)) {
document.getElementById(which2).style.marginTop = Math.floor( (document.getElementById(which2).parentNode.offsetHeight - document.images[which2].height) / 2 ) + 'px';
var newi = i + 1; centerit(which, newi);
}
}
setTimeout("centerit('centered', 1)", 1);
</script>
<div style="background-image: url('url of image'); background-repeat: no-repeat; background-position: center; width: 64px; height: 64px"><a href="link to page"><img src="transparent gif" width="64" height="64"></a></div>
In addition, the center baseline is only relative to the nbsp. I havent found a way to align the nbsp to the div.
My website is a bit more stable now, and Ive put it in my profile, so you can have a look and see what Ive done regarding this problem. Its not finished yet.