css - how to fit image without stretching and maintain aspect ratio in div tag in html -


my image size 640*820.and want fit image screen of size 310*520. while doing maintain aspect ratio(without stretch).

<div class="abc" style="     background: url("images/phone.png");     position: absolute;     max-width: 100%;     width: auto;     margin-left:10px;     background-size: contain;     top: 50px;"> 

you state width of image , have height auto

.div img {    width: 310px;    height: auto; } <div class="div">   <img src="#" title="#"> </div> 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -