image - Forcing aspect ratio with CSS doesn't work on Safari -
the following code works in firefox , chrome, doesn't in safari (tested on mac , ipad): http://jsfiddle.net/efd87/.
<div id="wrapper"> <div id="content"> <img src="http://farm3.staticflickr.com/2783/4106818782_cc6610db2c.jpg"> </div> </div> #wrapper { position: relative; padding-bottom: 33.33%; /* set ratio here */ height: 0; } #content { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: green; text-align: center; } #content img { max-height: 100%; } the goal have wrapper div keep fixed aspect ratio (in web application carousel), , image inside resize fit in div (and center).
on safari image doesn't display because of height: 0 (which give height of 0 img). height: 100% image display doesn't fit div (it overflows).
do see solution problem? i've been on hours...
this isn't great answer question it's answer nonetheless.
i doubt possible using css approach because far know (i'm happy corrected on this) there no way perform calculations based on of css property. width: height * 1.3; example isn't possible. can't use % either because that's percentage of parent, not of self.
the way looking @ involving bottom padding won't work reliably either, work on screen if else screen has different aspect ratio or have lots of tool bars changing aspect ratio of browser window aspect ratio wrong. % of parent unless can guarantee size of cannot use.
so far can tell option on javascript. obvious , recommendation jquery or other framework calculate , explicitly set height based on width. don't forget listen browser window resizing though.
Comments
Post a Comment