Hey there! I’m practicing with flexbox on a navigation bar, but when I try to aplly the propertie “align-items” on the container nothing happens.
This is the code:
.container {
border: solid black 2px;
display: flex;
height: 100%;
align-items: center;
}
and this is the (no)result:
I tried also the “align-self” in ever child item but it doesn’t work either and I can’t seem to understand where the problem is. If anyone can help I’ll be very thankful!
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).
1 Like
Hola @felinacosmica,
Todo bien?
The problem may be that the height of the items occupies 100% of the container’s height. Try giving the items a height that is less than the container’s (something like 50% for example), and then you’ll be able to see the effect of the align-items: center
property.
If it’s still not doing what you want, let me know.
PS: Spanish is my first language, so if you’d prefer to ask me something in spanish (by PM), feel free to do that if it’s easier for you.
1 Like
You use justify content for this case as the default flex direction is row. Plus you have no vertical space left for align items to work.
This might help
1 Like
Thank you both! Clearly, the problem was that the items occupied the 100% of the container’s height. I just set their height to ‘auto’ and the problem was solved.
Y gracias @johnsciutto, está bueno saber que hay gente que habla español también! jaja
1 Like