Top community members
All Wiki Articles Create Wiki Article

Many years me and my friends we were volunteers on my university doing programming classes for young people.

I got main conclusion: Young people are awesome, especially students, because they always bring new and fresh ideas :)
* I loved to do it but my time is limited

  I decided to create something that will help millions of students

Now I am here

co-founder

CSS - how to align element to left and right with flex?

0 contributions
13 points

Using Flexbox it is possible to align child elements in few ways.

1. Spacer element between example

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    .parent {
      	border: 1px solid red;
    	display: flex;
    }
    
    .child {
    	padding: 10px;
    }
    
    .left-child {
    	background: lightgreen;
      	flex: 0;
    }
    
    .spacer {
      	background: ivory;
    	flex: auto;
    }
    
    .right-child {
    	background: lightblue;
    	flex: 0;
    }
    
  </style>
</head>
<body>
  <div class="parent">
    <div class="child left-child">LEFT</div>
    <div class="child spacer">SPACER</div>
    <div class="child right-child">RIGHT</div>
  </div>
</body>
</html>

2. space-beetwen container style example

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    .parent {
      	border: 1px solid red;
    	display: flex;
      	justify-content: space-between;
    }
    
    .child {
    	padding: 10px;
    }
    
    .left-child {
    	background: lightgreen;
      	flex: 0;
    }
    
    .right-child {
    	background: lightblue;
    	flex: 0;
    }
    
  </style>
</head>
<body>
  <div class="parent">
    <div class="child left-child">LEFT</div>
    <div class="child right-child">RIGHT</div>
  </div>
</body>
</html>

3. auto margin example

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    .parent {
      	border: 1px solid red;
    	display: flex;
    }
    
    .child {
    	padding: 10px;
    }
    
    .left-child {
      	margin-right: auto;
    	background: lightgreen;
      	flex: 0;
    }
    
    .right-child {
      	/* margin-left: auto; */
    	background: lightblue;
    	flex: 0;
    }
    
  </style>
</head>
<body>
  <div class="parent">
    <div class="child left-child">LEFT</div>
    <div class="child right-child">RIGHT</div>
  </div>
</body>
</html>

 

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more