Placing a div below another (using flexbox)

I am trying to place timeAgoie content 22 seconds agojust below the content info. But for the style that I use, it timeAgopushes to the right.
Here is my markup -

.container {
		
		overflow:auto;
		
	}
	.post {
		height:120px;
		width:700px;
		margin:120px auto;
		background-color:#EFEFEF;
		border:1px solid #79CEF4;
		display:flex;
		justify-content:flex-start;		
	}
	
	
	.photo {
		width:80px;
		height:80px;
		background-color:#99E058;
		margin:10px 10px 10px 20px;
		align-self:center;
		
	}
	
	.info {
		
		margin: 25px 10px 10px 20px;
		align-self:center;
		
	}
	
	.timeAgo {
		margin: 80px 10px 10px 20px;
		font-size:11px;
		
	}
<div class="container">

     <div class="post">
        
        <div class="photo"></div>
        <div class="info"><p>This is just a plain simple message!</p></div>
        <div class="timeAgo">22 seconds ago</div>
    
     </div>
    
    </div>
Run codeHide result
+4
source share
3 answers

The simplest task is to customize the HTML.

.post {
  height: 120px;
  width: 700px;
  margin: 20px auto;
  background-color: #EFEFEF;
  border: 1px solid #79CEF4;
  display: flex;
  align-content: center;
  justify-content: flex-start;
}
.imgwrap {
  text-align: center;
}
.photo {
  width: 80px;
  height: 80px;
  background-color: #99E058;
  margin: 10px 10px 10px 20px;
}
.info {
  margin: 25px 10px 10px 20px;
}
.timeAgo {
  font-size: 11px;
}
<div class="post">
  <div class="imgwrap">
    <div class="photo"></div>
    <div class="timeAgo">22 seconds ago</div>
  </div>
  <div class="info">
    <p>This is just a plain simple message!</p>
  </div>


</div>
Run codeHide result

BUT ... if you cannot do this, you will need to allow the flex container wrapper to wrap and force the div to timeAgobe forced to the second line.

One of the methods:

.post {
  height: 120px;
  width: 700px;
  margin: 20px auto;
  background-color: #EFEFEF;
  border: 1px solid #79CEF4;
  display: flex;
  align-content: center;
  flex-wrap: wrap;
}
.photo {
  flex: 0 0 80px;
  height: 80px;
  background-color: #99E058;
  margin: 10px 10px 0px 10px;
}
.info {
  flex: 1;
  display: flex;
  align-self: center;
}
.timeAgo {
  flex: 0 0 100%;
  font-size: 11px;
  margin: 10px;
}
<div class="post">

  <div class="photo"></div>


  <div class="info">
    <p>This is just a plain simple message!</p>
  </div>

  <div class="timeAgo">22 seconds ago</div>
</div>
Run codeHide result
+3
source

This is a much simpler answer. Use flex-direction: column;!

.post {
    height:120px;
    width:700px;
    margin:120px auto;
    background-color:#EFEFEF;
    border:1px solid #79CEF4;
    display:flex;
    justify-content:flex-start; 
    flex-direction: column; /*This solves everything*/
}
+14
source

, ;

.timeAgo {
    margin: 80px 10px 10px -260px;
    font-size:11px;
}
0

Source: https://habr.com/ru/post/1613088/


All Articles