Place single child at bottom of flex container flex-direction colum? [duplicate] - css

This question already has answers here:
Center and bottom-align flex items
(3 answers)
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Closed 8 months ago.
HTML:
<div class="wrapper">
<div class="child1"></div>
<div class="child2"></div>
</div>
CSS:
.wrapper {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
I have two child, I want the first to be at center of page and only the second to be at bottom without using position absolute or affecting first child positioning

Related

Css - vertical centering of an image inside a div [duplicate]

This question already has answers here:
How to vertically align an image inside a div
(37 answers)
Flexbox: center horizontally and vertically
(14 answers)
How can I vertically align elements in a div?
(28 answers)
Closed 2 years ago.
here HTML:
<div class="user-image text-center">
<img class="avatars" src="css/img/avatar_1.jpg" alt="">
</div>
here CSS:
.user-image {
height: 10vh;
width: 15%;
float: left;
}
I'm trying to centering vertically my image inside my DIV (it's a square) but I'm a beginner and can't find the correct way. I tried vertical-align: middle; and margin: auto; but nothing. Can you suggest me some methods for that?
Use flex styles.
.user-image {
display: flex;
justify-content: center;
align-items: center;
}

How to align flexbox items to the most left, the most right and center? [duplicate]

This question already has answers here:
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Closed 2 years ago.
I have a flexbox container row and there are three items inside. I want one of them to be in the very center but I want the other two 2 to be slightly over it and to the most left and to the most right respectively. I want something like this:
I tried with aligning and justify content but it did not work.
Thanks in advance.
Here is an illustration of what you want. Just give the middle element a margin-top:
.container {
display: flex;
justify-content: space-between;
}
.container div {
width: 50px;
height: 100px;
background-color: red;
}
.center {
margin-top: 50px;
}
<div class="container">
<div class="right"></div>
<div class="center"></div>
<div class="left"></div>
</div>

Right align all elements when text makes a new line [duplicate]

This question already has answers here:
Make container shrink-to-fit child elements as they wrap
(4 answers)
CSS when inline-block elements line-break, parent wrapper does not fit new width
(2 answers)
Closed 2 years ago.
I have a set of divs and want the children to be right aligned:
.parent {
width: 150px;
border: solid;
display: flex;
align-items: center;
justify-content: flex-end;
}
<div class="parent">
<div class="icon">x
</div>
<div>Toooooooo looooooooong</div>
</div>
When the text breaks in a newline, it still occupies all the space, so it's not at the right. I could use width: min-length, but then all the short texts with spaces break in a new line, and I want it only for the long ones.
Here's the example in CodePen: https://codepen.io/rveciana/pen/eYpyKJX

Vertical Center with Flexbox and alignment of child items [duplicate]

This question already has answers here:
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 3 years ago.
Only getting around to trying out flexbox now and I'm using it to vertically center content inside a div.
.parent{
display: flex;
align-items: center;
justify-content: center;
}
<div class="parent">
<h1>Title</h1>
<p>Paragraph one.</p>
<p>Paragraph two.</p>
</div>
So when I do this it works but the child elements are placed beside each other like they're not block items anymore. How can I have it that they're vertically centered but stacked on top of each other?
Cheers!
If you want to show elements in column you need to use flex-direction: column style property.
.parent{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
<div class="parent">
<h1>Title</h1>
<p>Paragraph one.</p>
<p>Paragraph two.</p>
</div>

Vertically centered: Parent element with 2 child elements [duplicate]

This question already has answers here:
Flexbox: center horizontally and vertically
(14 answers)
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Closed 3 years ago.
Please have a look at this code:
<div class="parent">
<header class="child-1">
<h1 class="float-left">lorem...</h1>
<div class="float-right">lorem...</div>
</header>
<div class="child-2">lorem...</div>
</div>
CSS looks like:
.parent {
display: flex;
align-items: center;
}
Applying this causes both child-1 and child-2 centered vertically in one line. I need that child-2 should start from line2, i.e., right below child-1.
Thanks in advance
Set the flex-direction:
.parent {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
height: 100%;
}
<div class="parent">
<header class="child-1">
<h1 class="float-left">lorem...</h1>
<div class="float-right">lorem...</div>
</header>
<div class="child-2">lorem...</div>
</div>
Then you probably want to adjust the align-items as I'm assuming you don't actually want to center everything horizontally.
.parent {
display: flex;
flex-direction: column;
align-items: center;
}

Resources