Hey Jackson! I have a suggestion for you that involves some HTML rewriting, which might be the most effective solution for your issue.
You can start by creating a hidden image with encoded database info using <img>
:
img#imgUtility {
display: none;
}
(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}" />
After the page loads and the image's URL is resolved, you can replace the <img>
with a <span>
in your HTML and set the hidden tag's src
as the background image of the <span>
using JavaScript:
// Make sure galleryBoxLinkTarget refers to the <a> inside div.galleryBox
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);
}
(JavaScript and HTML)
<div class="gallerybox">
<a href="/CustomContentRetrieve.aspx?ID=398791">
<!-- <span> goes here -->
</a>
</div>
Finally, add some CSS magic:
span.imgReplacement {
display: block;
background-position: 50% 50%;
background-repeat: no-repeat;
width: 200px;
height: 200px;
}
This method will center the picture regardless of dimension and allow you to remove inline width
and height
. Happy coding!