简体   繁体   English

Flex-grow 在 Angular 中不起作用<router-outlet></router-outlet>

[英]Flex-grow does not work in Angular for <router-outlet>

I create a web application with Angular.我使用 Angular 创建了一个 web 应用程序。 I wanted to make a footer that will be at the bottom of the page.我想制作一个位于页面底部的页脚。 If the content of the page was small, the footer would still be at the bottom, not in the middle of the page.如果页面内容很小,页脚仍然会在底部,而不是在页面中间。 For this, I wrote code to push the contents of the <router-outlet> directive down the page.为此,我编写了代码将<router-outlet>指令的内容推送到页面下方。 But unfortunately it doesn't work.但不幸的是,它不起作用。

This my code in css (code from the styles.css file):这是我在 css 中的代码(来自 styles.css 文件的代码):

#portal-wrapper {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

router-outlet {
  flex-grow: 1;
}

app-menu, router-outlet, app-footer {
  flex-shrink: 0;
}

This is the content of my app.component.html file:这是我的 app.component.html 文件的内容:

<div id="portal-wrapper">
  <app-menu></app-menu>
  <div id="portal">
      <div class="container">
          <router-outlet></router-outlet>
        <div class="row">
          <app-footer></app-footer>
        </div>
    </div>
  </div>
</div>

Theoretically, the content should be pushed down (more precisely, the empty space below it) so that the footer is at the bottom of the page.理论上,内容应该被下推(更准确地说,是它下面的空白区域),这样页脚就在页面的底部。 flex-grow: 1; for <app-menu> works and pushes <router-outlet> down.对于<app-menu>起作用并将<router-outlet>向下推。 Any suggestions why <router-outlet> doesn't push footer down?有什么建议为什么<router-outlet>不向下推页脚?

div with portal-wrapper has two child ie <app-menu> and div portal , when make portal-wrapper into a flexbox you can use flex-grow: 1 only for its child.带有portal-wrapper div 有两个子元素,即<app-menu>和 div portal ,当将portal-wrapper制作成 flexbox 时,您可以仅将flex-grow: 1用于其子元素。

flex-grow: 1; for <app-menu> works and pushes <router-outlet> down.对于<app-menu>起作用并将<router-outlet>向下推。

It's actually pushing the div portal down and not just the <router-outlet>它实际上将 div portal向下推,而不仅仅是<router-outlet>

You should make div container into flexbox and add flex-grow: 1 to <router-outlet> .您应该将 div container放入 flexbox 并将flex-grow: 1添加到<router-outlet>

HTML<textarea> <i>does not respect "flex-grow"</div></i><b>不尊重“弹性增长”</div></b></textarea><div id="text_translate"><p> 在下面的代码片段中,您可以看到<div>变大了,但<textarea>没有变大,为什么? 在 Chrome 和 Firefox 中是一样的。 </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> details { display: flex; width: 100%; background: gray; } div, textarea { display: block; flex-grow:1; background: red; margin-left: 32px; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> <details open> <summary> Summary </summary> <textarea>text area does not grow</textarea> <div>Div does grow</div> </details></pre></div></div><p></p></div> - HTML <textarea> does not respect "flex-grow"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让 flex-grow 在 Angular 10 中与 *ngFor 一起使用 - How to get flex-grow to work with *ngFor in Angular 10 如何获得Angular的 <router-outlet> 使用CSS Grid - How to get Angular's <router-outlet> to work with CSS Grid flex-grow 属性似乎无法正常工作 - The flex-grow property seems not work properly HTML<textarea> <i>does not respect "flex-grow"</div></i><b>不尊重“弹性增长”</div></b></textarea><div id="text_translate"><p> 在下面的代码片段中,您可以看到<div>变大了,但<textarea>没有变大,为什么? 在 Chrome 和 Firefox 中是一样的。 </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> details { display: flex; width: 100%; background: gray; } div, textarea { display: block; flex-grow:1; background: red; margin-left: 32px; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> <details open> <summary> Summary </summary> <textarea>text area does not grow</textarea> <div>Div does grow</div> </details></pre></div></div><p></p></div> - HTML <textarea> does not respect "flex-grow" `flex-grow:0` 是如何解释的? - How does `flex-grow:0` get interpreted? 填充多行 flex 布局中剩余的水平空间(“flex-grow:1”不起作用) - Fill remaining horizontal space in multirow flex layout ("flex-grow: 1" does not work) 了解 flex-grow - Understanding flex-grow 页脚适用于 Angular<router-outlet></router-outlet> - Footer works with Angular <router-outlet> 如何使用多个<router-outlet>与 Angular</router-outlet> - How to use multiple <router-outlet> with Angular flex 或 flex-grow, flex-grow 或 flex - flex or flex-grow, flex-grow or flex
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM