垂直6至50至50高度的Angular 6的柔性布局

时间:2018-09-27 14:42:38

标签: css angular flexbox angular6 angular-flex-layout

我在Angular6中使用了FlexLayoutModule,并试图实现两个垂直高度均为50%的div。我已经试过这个特殊的代码,但是两者都不占据父级的50%。

<div style="min-height:50px">I'm header</div>
<div style="height:100%">
<div fxLayout="column" fxLayoutGap="12px">
    <div fxFlex="50%" style="background:#5896FF">
        <h1>I should occupy 50% height of my parent</h1>
    </div>
    <div fxFlex="50%" style="background:#525252">
        <h1>I should occupy 50% height of my parent</h1>
    </div>
</div>

Link of so far working example

This is what I'm trying to achieve

2 个答案:

答案 0 :(得分:0)

您可以使用50vh代替50%。它将使用垂直高度的50%。

<div fxLayout="column" fxLayoutGap="12px" style="">
<div fxFlex="50vh" style="background:#5896FF">
    <h1>I should occupy 50% height</h1>
</div>
<div fxFlex="50vh" style="background:#525252">
    <h1>I should occupy 50% height</h1>
</div>

答案 1 :(得分:0)

我对您的示例进行了几处更改,以使两个div在屏幕上垂直分割50/50。

<div style="height:100%" fxLayout="column">
    <div style="min-height:50px">I'm header</div>
    <div fxLayout="column" fxLayoutGap="12px" fxFlex>
        <div fxFlex style="background:#5896FF">
            <h1>I should occupy 50% height of my parent</h1>
        </div>
        <div fxFlex style="background:#525252">
            <h1>I should occupy 50% height of my parent</h1>
        </div>
    </div>
</div>

您还需要更新styles.css:

html, body {
    height: 100%;
    margin: 0;
}

Here is a link to the updated example.