{"id":235148,"date":"2015-11-24T07:09:20","date_gmt":"2015-11-24T14:09:20","guid":{"rendered":"http:\/\/css-tricks.com\/?p=235148"},"modified":"2017-05-04T08:55:34","modified_gmt":"2017-05-04T15:55:34","slug":"scaled-proportional-blocks-with-css-and-javascript","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/scaled-proportional-blocks-with-css-and-javascript\/","title":{"rendered":"Scaled\/Proportional Content with CSS and JavaScript"},"content":{"rendered":"
The web is a fluid place. Different sized screens, yadda yadda yadda. Fortunately for us, the web is ready for it. Text wraps. CSS gives us control over how to size things. What we don’t get (easily, anyway) is a way to scale whole element (and it’s children) proportionally—retaining its exact layout as it changes size.<\/p>\n
We can do it though.<\/p>\n
<\/p>\n
Uncle Dave’s Ol’ Padded Box:<\/a><\/p>\n Then if you want content inside, you can absolutely position a covering container inside:<\/p>\n This can be quite useful for things like images, containers that can independently scroll, or containers with so much spare room that it can handle dramatic changes in shape.<\/p>\n If the content of this container was, say, an image<\/a>, it works great!<\/p>\n.parent {\r\n height: 0;\r\n padding-bottom: 56.25%; \/* 16:9 *\/\r\n position: relative;\r\n}<\/code><\/pre>\n
.child {\r\n position: absolute;\r\n top: 0; left: 0;\r\n width: 100%; height: 100%;\r\n}<\/code><\/pre>\n