javascript - CSS: How to scale an <img> to cover entire parent <div>? -
question:
the <img>
isn't shrink wrapping expect min-width:100%
i'm trying shrink <img>
until either height or width matches container
click anywhere in <iframe>
toggle container shapes
please try edit
<img>
css:1) maintain aspect ratio
2) cover entire surface area of container div
3) only edit image
this centering approach looks kinda sketch it's pretty robust
my question specifically: scale <img>
fill (maintain aspect ratio cover entire surface) of parent <div>
parent <div>
resizes
maybe somehow use css flex box-layout or something? maybe transform?
answer:
set html source transparent base64 pixel (credit css tricks)
<img id="img" src="data:image/gif;base64,r0lgodlhaqabaiaaaaaaap///yh5baeaaaaalaaaaaabaaeaaaibraa7" />
use css background property
#img { width: 100%; height: 100%; background: url(http://i.imgur.com/0bbscub.gif) no-repeat center; background-size: cover; }
if don't want touch container, put background on <img>
#img { background: url(imgpath) no-repeat center; background-size: cover; }
Comments
Post a Comment