HTML CSS examples for CSS Layout:Flex Container
Nested Flexbox stretches Image
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style id="compiled-css" type="text/css"> .main-container{<!--from w w w . j a v a 2 s. c o m--> position: absolute; top:0; left:0; width:100%; height:100%; display: flex; flex-direction: column; } .header, .footer{ width:100%; height: 1em; background-color: red; } .image-container{ height: 100%; background-color: green; display: flex; justify-content: center; align-items: center; position:relative; } .image-container img{ position:absolute; top:0; bottom:0; right:0; left:0; margin:auto; max-height:100%; max-width: 100%; } </style> </head> <body> <div class="main-container"> <div class="header"> header </div> <div class="image-container"> <img src="https://www.java2s.com/style/demo/InternetExplorer.png"> </div> <div class="footer"> footer </div> </div> </body> </html>