css - Angular 6 垂直 50-50 高度的 flex 布局

标签 css angular flexbox angular6 angular-flex-layout

我将 FlexLayoutModule 与 Angular6 一起使用,并尝试实现两个垂直高度均为 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

最佳答案

我对您的示例进行了一些更改,使两个 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.

关于css - Angular 6 垂直 50-50 高度的 flex 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52539597/

相关文章:

Angular Material 2 : Progress Bar animation choppy

php - 飞行响应中的 Access-Control-Allow-Headers 不允许请求 header 字段 Content-Type

javascript - 嵌套 DOM 生成错误

html - 无法滚动到容器溢出的 flex 元素顶部

html - 如何像谷歌为其官方博客做这种css3动画

html - 从 Blogger 帖子中删除 adsense

javascript - 如何使特定按钮保持事件状态? CSS,Javascript

html - 2 列,宽度为 100% bootstrap 3

angularjs - Angular 从 1.6.6 升级到 6 时出现 $Injector 错误

html - 为什么 flex 元素不缩小过去的内容大小?