CSS Flexbox - Use display: flex to Position Two Boxes

CSS Flexbox - Use display: flex to Position Two Boxes

Placing the CSS property display: flex; on an element allows you to use other flex properties to build a responsive page.

imagine you have to divs that want to display side by side in one container
first we should give display: flex; on that container and give 50% for width and height for both contained boxes as follow:

<style>
  #box-container {
    height: 500px;
    display:flex;
  }
  
  #box-1 {
    background-color: dodgerblue;
    width: 50%;
    height: 50%;
    
  }

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

see the result now for that code

as we see the two boxes are displayed as one row as the flex 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