CSS Flexbox: Use the flex-basis Property to Set the Initial Size of an Item

  The flex-basis property specifies the initial size of the item before CSS makes adjustments with flex-shrink or flex-grow.
The units used by the flex-basis property are the same as other size properties (px, em, %, etc.). The value auto sizes items based on the content.

consider this flex-box containing two boxes  box1  and box2 that they do not have width property set .
i add text inside them so they will appear as text wide only.
 

box1
box2
html code


<style>
  #box-container {
    display: flex;
    height: 300px;
  }
  
  #box-1 {
    background-color: dodgerblue;
    height: 200px;

    
  }
  
  #box-2 {
    background-color: orangered;
    height: 200px;
    
  }
</style>
  
<div id="box-container">
  <div id="box-1"></div>
  <div id="box-2"></div>
</div>

Now lets add flex-basis to each boxes 10em for box1  and 20em for box2



html code
<style>
  #box-container {
    display: flex;
    height: 300px;
  }
  
  #box-1 {
    background-color: dodgerblue;
    height: 200px;
    flex-basis:10em;
    
  }
  
  #box-2 {
    background-color: orangered;
    height: 200px;
    flex-basis:20em;
  }
</style>
  
<div id="box-container">
  <div id="box-1"></div>
  <div id="box-2"></div>
</div>
source

Comments

Popular posts from this blog

ES6 : 5 Prevent Object Mutation

ES6: 1 Explore Differences Between the var and let Keywords

CSS Grid: Reduce Repetition Using the repeat Function