Note that there are some explanatory texts on larger screens.

plurals
  1. POProportional resize of the dynamically loaded images and centering them vertically and horizontally
    primarykey
    data
    text
    <p>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 <strong>load the images dynamically</strong>:</p> <pre><code>$(function(){ $.getJSON("inc/API.php", {command:"top3"}, function(result) { for(var i = 0; i&lt;result.length; i++) { $("&lt;div id='top3imgContainer'&gt;&lt;a href='images/" + result[i].imageFileName + "' rel='shadowbox[top3]' title='" + result[i].imageHeader + "'&gt;&lt;img width='220' height='220' src='images/" + result[i].imageFileName + "' id='top3img' /&gt;&lt;/a&gt;&lt;/div&gt;").appendTo("#divTop3"); } Shadowbox.init({ continuous:true, displayCounter:false, overlayColor:"#a09e92", overlayOpacity:0.8 }); }); }); </code></pre> <p><strong>The HTML</strong>:</p> <pre><code>&lt;div id="divContent"&gt; &lt;div id="divTop3"&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>This is <strong>the CSS</strong>:</p> <pre><code>#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; } </code></pre> <p>And after applying the CSS this is how it looks: <a href="http://i44.tinypic.com/168x7i9.jpg" rel="nofollow">http://i44.tinypic.com/168x7i9.jpg</a></p> <p>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?</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload