keep aspect ratio of image inside flexbox with flex:1 - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Flex Container

Description

keep aspect ratio of image inside flexbox with flex:1

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">

.slider {<!-- ww w . j  a va 2  s .  c  om-->
   display: flex;
   flex: 1;
   align-items: center;
}
.slider img {
   width: 100%;
}


      </style> 
 </head> 
 <body> 
  <div class="slider"> 
   <img src="https://www.java2s.com/style/demo/Safari.png" alt="Bacn"> 
  </div>  
 </body>
</html>

Related Tutorials