[英]Flexbox wont vertically centre child elements of parent
I have a parent container div and some child elements however only one child element is being vertically centred.我有一个父容器 div 和一些子元素,但是只有一个子元素垂直居中。 I cant figure out what i am doing incorrect.
我无法弄清楚我在做什么不正确。 The instagramwrapper is being vertically aligned but the wrapper containing two other child elements remains up the top of the page.
instagramwrapper 是垂直对齐的,但包含其他两个子元素的包装器仍然位于页面顶部。
html: html:
<div class="Container">
<div class="headerWrapper">
<div>
<span>Information & Advice</span>
</div>
<div>
<span>From the daylight experts</span>
</div>
</div>
<div class="wrapper">
<app-carousel></app-carousel>
<app-guides></app-guides>
</div>
<div class="instagramWrapper">
<app-instagram></app-instagram>
</div>
css: css:
.Container {
padding: 0;
height: 100%;
margin: 0;
display: flex;
align-self: center;
align-items: center;
justify-content: center;
flex-direction: row;
width: 100%;
}
.wrapper {
width: 780px;
/* inherit parent width */
}
.instagramWrapper {
width: 500px;
padding-left: 10px;
margin-left: 2px;
/* inherit parent width */
}
It was my understanding that 'align-items' can be aligned in the cross axis of the current line of the flex container?我的理解是 'align-items' 可以在 flex 容器当前行的横轴上对齐?
new result ^新结果^
Your container might have height of 100%.您的容器可能具有 100% 的高度。 But does it's parent have a height of 100%?
但它的父级是否有 100% 的高度?
try the following:尝试以下操作:
html, body {
height: 100%;
}
This will give the document a height of 100% of the viewport, so that the .Container gets 100% of the document.这将使文档具有 100% 视口的高度,以便 .Container 获得 100% 的文档。
And both of your inner Elements (instafeed and the column on the left) will be positioned differently, depending on their size.并且您的两个内部元素(instafeed 和左侧的列)的位置将有所不同,具体取决于它们的大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.