So, for centuries I tried to achieve this. Basically, my site allows the administrator to upload a thumbnail and a thumbnail image for each item in the directory. The thumbnail is displayed on the page that the client sees, and the magnification is displayed when you hover over it.
I cannot control the size of the uploaded images (I suppose I could limit the width and height, but in this situation it would be impractical).
I would like to vertically and horizontally center this zoom. It is contained in a div with position: fixed; . I believe (although I donβt have the code in front of me at the moment) that I am currently using something like the following:
.image-enlargement { position: fixed; left: 50%; top: 50%; width: 300px; height: 400px; margin-left: -150px; margin-top: -200px; }
Perhaps I changed it to use jQuery - I donβt remember, although it was so long ago when I last worked on this fragment of the website. Now, what I would like to do with the code above is to subtract the specifications for width, height, and margin so that the image, no matter how large or small, should be accurately centered and without using JavaScript.
Has anyone ever done this before? If so, how? I am sure there must be some way to achieve this result, but it did not come up with a pure CSS / HTML solution.
Edit: JSFiddle at http://jsfiddle.net/Y7xAp/ .
source share