1
I’m having a problem, I don’t quite understand the concept of Align-items in flexbox, I don’t know why it’s not working, follow code:
<div style="display: flex; align-items: center; justify-content: center">
<div style="background-color: red; height: 250px; width: 250px">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aliquid animi architecto beatae
debitis dignissimos dolore et id magnam molestias nisi perferendis perspiciatis,
qui quis quo quod sed vero voluptas voluptatum.</p>
</div>
</div>
I think he wanted to align the text on the red div. D
– Sam
So by default the elements have to be set at the correct height and width? To be able to work with display: flex.
– Rafael Balmant
@Rafaelbalmant not necessarily as you saw it. In its code the element was already centered horizontally because the DIV had by default the width of 100% of the screen. Then the justfy-contented worked as expected. For you to align vertically it is necessary to have some height set somewhere, because as you will align in the center of 0. Even if the height of the father is 100%, or 100VH or something like that it is important that it has some value... And the alignment with flex is always the alignment of the child in relation to the father. Father with Flex, ai vc aligns the Son with the properties of flex.
– hugocsl
...continuing @Rafaelbalmant and when the Father has flex the son tb gains some properties to align individually within the father, are the propriedads ended in
-self
type, aling-self or justfy-self– hugocsl
@Sam when I hit my eye and I thought it was this rss, but after I saw that the styles were in the container of "out" I called it could be as I mentioned in the reply...
– hugocsl
@hugocsl, got it. Thank you so much for the help gave a monstrous help here. Really worth :)
– Rafael Balmant
@Rafaelbalmant inclusive, se vc recortar os estilos Flex do container Pai, e colar junto dos estilos Filho, box vermelho, vc vai ver que o texto tb vai alinhar no centro do box. I’m glad I did. after a look at this guide https://css-tricks.com/snippets/css/a-guide-to-flexbox/
– hugocsl
@Rafaelbalmant If my reply has helped you in any way consider marking it as Accept, in this icon
✔
below the arrows on the left side of my answer :) so the site does not get open questions pending without accepted answer. Abs– hugocsl