Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display child div on the end of parent flex row div and another two divs on the start of parent div? [duplicate]

Tags:

html

css

flexbox

How is it possible to display two div containers on the start of a row flex parent and the third one at the end? child-3 should be on the right side in the example below.

Here is a quick sample with all cildren on the start of the parent: jsfiddle

.parent {
  height: 50px;
  width: 100%;
  border: 1px solid red;
  display: flex;
  flex-direction: row;
}

.child-1,
.child-2,
.child-3 {
  margin: 2px 1px;
  padding: 2px;
  border: 1px solid blue;
}

.child-1 {}

.child-2 {}

.child-3 {}
<div class="parent">
  <div class="child-1">
    child-1
  </div>
  <div class="child-2">
    child-2
  </div>
  <div class="child-3">
    child-3
  </div>
</div>
like image 695
JohnDizzle Avatar asked Aug 17 '17 08:08

JohnDizzle


1 Answers

just add margin-left: auto;

.parent {
    height: 50px;
    width: 100%;
    border: 1px solid red;
    display: flex;
    flex-direction: row;
}

.child-1,
.child-2,
.child-3 {
    margin: 2px 1px;
    padding: 2px;
    border: 1px solid blue;
}

.child-1 {}

.child-2 {}

.child-3 {
    margin-left: auto;    /* new line added */
}
<div class="parent">
		<div class="child-1">
			child-1
		</div>
		<div class="child-2">
			child-2
		</div>
		<div class="child-3">
			child-3
		</div>
	</div>
like image 87
bhv Avatar answered Oct 03 '22 19:10

bhv