Maybe something like the following:
<div class ="gallerybox" >
<a href ="/CustomContentRetrieve.aspx?ID=398791" >
<img id ="imgUtility" class ="galleryImage" alt ="" src ="/Utilities/ShowThumbnail.aspx?USM=1& W=400& H=400& R=1& Img={tag_image_value}" /> " />
</a >
</div >
.gallerybox {
width:200px;
height:200px;
overflow:hidden;
}
<script language ="javascript" >
window .onload = fixImage;
function fixImage ( ) {
var img = document .getElementById ('imgUtility' );
var x = img.offsetWidth ;
var y = img.offsetHeight ;
img.style .left = -(x / 2 );
img.style .top = -(y / 2 );
}
</script >
Copy
Jackson. I'm going to recommend a bit of an HTML rewrite, which I understand may not be possible, but I think this might be the most effective solution to your problem.
Create a hidden image with that database encoded <img>
:
img #imgUtility {
display : none;
}
Copy
(CSS and HTML)
<img id ="imgUtility" class ="galleryImage" alt =""
src ="/Utilities/ShowThumbnail.aspx?USM=1& W=350& H=350&
R=1& Img={tag_image_value}" />
Copy
Then after the page has loaded and image has resolved to an actual URL, you can replace the <img>
with a <span>
in your posted HTML, set the hidden tag src
to the background image of the <span>
using it's inline style
attribute via JavaScript:
function imgReplacement (galleryBoxLinkTarget ) {
var span = document .createElement ("span" );
var img = document .getElementById ("imgUtility" );
span.style .backgroundImage = "url('" + img.getAttribute ("src" ) + "')" ;
span.className = "imgReplacement" ;
galleryBoxLinkTarget.appendChild (span);
}
Copy
(JavaScript and HTML)
<div class ="gallerybox" >
<a href ="/CustomContentRetrieve.aspx?ID=398791" >
</a >
</div >
Copy
And then do a bit of clever CSS'ing:
span .imgReplacement {
display : block;
background-position : 50% 50% ;
background-repeat : no-repeat;
width : 200px ;
height : 200px ;
}
Copy
This should center the picture regardless of dimension, as well as allow you to remove the inline width
and height
attributes. Hope this works out for you!
Try this:
<style type ="text/css" >
.gallerybox {text-align :center;vertical-align :middle;height :400px ;line-height :400px ;}
.gallerbox img {display :inline; vertical-align :middle;}
</style >
<div class ="gallerybox" >
<a href ="/CustomContentRetrieve.aspx?ID=398791" >
<img alt ="" src ="/Utilities/image.jpg" />
</a >
Copy
Use a simple JQuery fn called center ( Usage: $(element).center() ):
jQuery.fn .center = function ( ) {
this .css ("position" ,"absolute" );
this .css ("top" , (($(window ).height () - this .outerHeight ()) / 2 ) + $(window ).scrollTop () + "px" );
this .css ("left" , (($(window ).width () - this .outerWidth ()) / 2 ) + $(window ).scrollLeft () + "px" );
this .css ("bottom" , (($(window ).width () - this .outerWidth ()) / 2 ) + $(window ).scrollLeft () + "px" );
return this ;
}
$(document ).ready (function ( ){
$(#imgUtility).center ();
)};
Copy
With the HTML:
<div class ="gallerybox" >
<a href ="/CustomContentRetrieve.aspx?ID=398791" >
<img id ="imgUtility" class ="galleryImage" alt ="" src ="/Utilities/ShowThumbnail.aspx?USM=1& W=400& H=400& R=1& Img={tag_image_value}" /> " />
</a >
</div >
Copy
Post a Comment for "Align Background Image Middle And Center"