javascript - Set height of div wrapper by image width size -
going try , re-explain trying here. seems there little confusion around div / img example. in short, trying create wrapper around image stays square, expands in size responsively browser window adjusts. image inside square adjust size within square wrapper (div) fill space. images pretty same width, height varies, , want position on top , hide bottom larger square wrapper. because square wrapper resize window cannot set size actual size div, adjust automatically.
hope helps.
so here came with. seems work part.
var divwidth = $('.photo').width(); $('.photo').height(divwidth); $(window).resize(function(){ var divwidth = $('.photo').width(); $('.photo').height(divwidth); });
anyone have suggestions add?
--- original description ----
i'm looking create responsive web page images. unfortunately not images have same height width ratio. thinking of creating wrapper around image set height current width of image, , rest hidden. looking best , simplest way this?
so creates 2 column list of items expand width of browser. unfortunate because of image sizes of items taller others. , want image in square box width equal widths conformity. don't want resize images height wise, fill 100% width wise, , overflow on bottom.
css
.listing ul {position:relative; display:block; padding:0; margin:0;} .listpeople li {list-style:none; float:left; position:relative; display:block; width:48.93617020799999%; height:auto; background:#fff; border:1px solid #d0d5d8; padding:12px; margin:0 15px 15px 0; } .listpeople li .user .photo { position:relative; display:block; background:#fff; box-shadow:0 1px 2px rgba(0,0,0,0.09); border:1px solid #ddd; padding:8px; margin:0; } .listing li .user .photo img { width:100%; height:auto; max-width:100%; vertical-align:middle; border:0; -ms-interpolation-mode:bicubic; padding:0; margin:0; } .listing li .content { float:left; position:relative; display:block; width:74.468085099%; height:100%; padding:0; margin:0; }
html
<pre> <div class="listing"> <ul> <li> <div class="user"> <div class="photo"> <a href="#"><img src="url" /></a> </div> <a class="button">follow</a> </div> <div class="content"> -- normal html formatting -- </div> </li> </ul> </div> </pre>
i set width of container , use attribute style="max-width:100%"
on img
tag.
<p><img src="http://whiterootmedia.com/images/css_rule.jpg" alt="css rule" style="max-width:100%" /></p>
here example: http://www.whiterootmedia.com/database/dusty_arlia/what_are_css_selectors.html