css - DIV wrapping around a IMG with 100% height -


i have div , img both set 100% height , widths auto.

but want div resize/wrap width of img (and maintain aspect ratio) while resizing height of browser. doesn't seem so. in browser. knows why behavior occurs?

div {     height:100%;     background:red;     display:inline-block;     padding:20px;     box-sizing:border-box; }  img {     height:100%;     display:block; }  <div>     <img src="http://upload.wikimedia.org/wikipedia/commons/e/e9/official_portrait_of_barack_obama.jpg"/> </div> 

you can try out here. div has red background. http://jsfiddle.net/jjktf/3/

thanks!

hey hope see mentioned below css

div {     background: none repeat scroll 0 0 red;     display: inline-block;     height: 100%;     max-width: 100%;     padding: 20px; }  img {     display: block;     height: auto;     max-width: 100%; } 

its working per requirement.......

demo

demo2


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -