I have a few dynamically loaded images, with width and height being set inside the code. Obviously it doesn’t scale them proportionally. This is the code I use to load the images dynamically:
$(function(){
$.getJSON("inc/API.php", {command:"top3"}, function(result) {
for(var i = 0; i<result.length; i++) {
$("<div id='top3imgContainer'><a href='images/" + result[i].imageFileName + "' rel='shadowbox[top3]' title='"
+ result[i].imageHeader + "'><img width='220' height='220' src='images/" + result[i].imageFileName + "' id='top3img' /></a></div>").appendTo("#divTop3");
} Shadowbox.init({
continuous:true,
displayCounter:false,
overlayColor:"#a09e92",
overlayOpacity:0.8
});
});
});
The HTML:
<div id="divContent">
<div id="divTop3">
</div>
</div>
This is the CSS:
#divContent {
width:860px;
border: 1px solid;
border-color: #dbd9ca;
border-radius: 10px;
-moz-border-radius: 10px;
margin:5px;
margin-top:20px;
margin-bottom:20px;
padding:5px;
clear:both;
margin-bottom:20px;
}
#divTop3 {
width:850;
text-align:center;
position:relative;
}
#top3imgContainer {
width:245px;
height:270px;
background-image:url(../images_ui/frame.png);
background-repeat:no-repeat;
display:inline-block;
margin: 0 15px 0 15px;
}
img#top3img {
border-radius: 10px;
-moz-border-radius: 10px;
margin-left:13px;
margin-right:20px;
margin-top:17px;
}
And after applying the CSS this is how it looks:
http://i44.tinypic.com/168x7i9.jpg
Not exactly proportional and not really centered.
So the question is – how can I scale them proportionally? And after that – how can I center each image in its div?
Thank you!
I did this: http://jsfiddle.net/ydZJk/
The main changes are these: