views:

195

answers:

1

How to create web page for comparing two images, preferably using only (X)HTML and CSS, without JavaScript and DHTML / AJAX?

The simplest solution would be to put two images side by side together, either touching or almost touching and centered both, or each centered in its own half of page. The problem in robust solution is with degradable part.

  • the two images in question doesn't need to have the same size, for example one can be resized version of the other image; one question would be whether to use HTML attributes to scale them to the same visual size, and whether to center two images or align them to center of the page if they have unequal width:

    |_______|_______|
    |___[xx][xxxx]___|
    

    (centered as a whole) vs

    |_______|_______|
    |____[xx][xxxx]__|
    

    (aligned to center of page)

  • the images might be wider than half of the page; I'd rather avoid horizontal scrolling, so perhaps in such case images instead of being side by side would be one above another, and this should be automatic, without using JavaScript to compare width of image with the width of browser window and changing layout on the fly.

    The layout in this case should look roghly like below:

    |____[xxxxxxx]___|
    |_____[xxxxx]____|
    

The goal of this is to have a way to compare images in a web interface for version control system.

+4  A: 

I wouldn't want them scaled to the same visual size in a version control diff system, but you could use:

<img width='x' height='y'>

to do that (or just specify width if you wanted each image to maintain its aspect ratio).

To make one fall below the other when they didn't fit horizontally, just float one of them to the left:

<html><body><p align='center'>
<img src='http://stackoverflow.com/content/img/so/logo.png' float='left'>
<img src='http://stackoverflow.com/content/img/so/logo.png'&gt;
</p></body></html>

(The purists won't like align='center' etc. - please imagine I've done that properly using CSS 8-)

RichieHindle
Yeah.. floating them will make them appear side by side when they fit, or fall below when they don't. You can use server side technologies (PHP, Python, RoR) if you need more control but are concerned about client-side compatibility.
Mark