html - Is there way to set empty div size like image size css -




i wonder if can set div ratio responsive image in css. example, have image (800px x 400px) , set css width:100%. when use desktop screen (widht: 1400px), image auto resize , full width of screen => image size (1400px x 700px). element, have set both width , height there way set empty width 800px , height 400px, , auto resize depends on screen size, , still keep ratio image.

thank you

if browser support allows you, may use viewport units convey aspect ratio div. rest handled browser.

you may define class names different sizes. 1 work 16:9 images is:

width: 100vw; height: 77.78vw; 

16 / 9 => 1.777777777777778; in case 100% width of viewport need 77.78% height of viewport applied element.

you can pre-define classes different aspect ratios or use simple js calculate this.

codepen (same below): https://codepen.io/mchaov/pen/vjrgya

html, body {    height: 100%;    margin: 0;    padding: 0;  }    div {    margin: 0;    padding: 0;    border: 1px solid red;  }    .autoscale-16-9 {    width: 100vw;    height: 77.78vw;  }
<div class="autoscale-16-9">auto scale div</div>





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -