Set equal widths for two divs side by side in a flexbox - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Flex Width

Description

Set equal widths for two divs side by side in a flexbox

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">

#outer {<!--  w ww .j  av a 2s  . co  m-->
   position: relative;
   height: 300px;
   display: inline-flex;
   justify-content: center;
   align-items: center;
   left: 50%;
   transform: translateX(-100%);
}
#outer::after {
   content: '';
   position: absolute;
   left: 0; top: 0;
   height: 100%;
   width: 200%;
   border: 1px solid blue;
}
.inner {
   border: 1px solid red;
}
.inner:nth-child(2) {
   position: absolute;
   left: 100%;
   width: 100%;
}


      </style> 
 </head> 
 <body> 
  <div id="outer"> 
   <div class="inner">
     Inner HTML content has larger natural width than the other 
   </div> 
   <div class="inner">
     This has a smaller natural width 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials