I have a page with a heading, paragraph and one image, which can have very different sizes / proportions.
I would like the image to adapt so that it either fills the maximum available height, or is limited by its width, without losing proportions, without causing scrolling.
this is my main configuration:
angular.module("myApp", ["ngMaterial"]);
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/angular_material/1.0.0-rc7/angular-material.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-messages.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angular_material/1.0.0-rc7/angular-material.min.js"></script> <div ng-app="myApp" layout="column" layout-fill> <div flex style="background: red;"> <h1>Title</h1> <p>Details. Blablabla.</p> </div> <div flex="60" style="background: blue;" object-fit="fill"> <img id="myImg" ng-src="http://placehold.it/200x400"/> </div> </div>
I have looked at many SO posts, websites, blogs, etc. I canβt figure out where to start doing this. Most articles about fluid images or responsive images only talk about scrollable web pages. Therefore, even a good link to this topic would be useful. Thanks.
EDIT: Updated debugged to use flex layout . As you can see, the image goes beyond the blue div. I used object-fit="content"; or object-fit="fill"; but no one limits the image to respecting the borders of the div
source share