javascript - CSS: Keeping a div's height relative to its width -


this question has answer here:

my question similar question: css: 100% width or height while keeping aspect ratio?

i have div position fixed. width of div must 100% , height 1/6th of width. there -webkit-calc() way of doing this?

note: js solutions not preferred zoom/orientation change can affect width/height.

is after? i'm not using -webkit-calc() @ all. i've inserted 1px 6px image outer div has position: fixed applied it, , set image have width of 100% , position: relative. have added inner div absolutely positioned high , wide ancestor.

now can change width of outer div, , images' width: 100% setting ensure both outer , inner div's guaranteed have height equal 1/6th of width (or @ least close equal can get, heights rounded off closest whole number of pixels). content go inside inner div.

html

<div>   <div></div>   <img src="https://dl.dropboxusercontent.com/u/6928212/sixbyone.png" /> </div> 

css

html, body {   margin: 0px;   padding: 0px; } div {   position: fixed;   width: 100%; } div > div {   position: absolute;   top: 0px;   right: 0px;   bottom: 0px;   left: 0px;       } img {   width: 100%;   display: block;         position: relative; } 

here's jsfiddle showing requested behaviour.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -