简体   繁体   English

Angular 13 应用程序中用于移动设备的主应用程序组件 html 文件中的容器 div 未占据整个视口高度

[英]Container div not occupying full viewport height in the main app component html file for mobile devices in Angular 13 app

I am developing an app with Angular 13. It should have a responsive design and should work well in mobile devices.我正在使用 Angular 13 开发一个应用程序。它应该具有响应式设计,并且应该在移动设备中运行良好。 The code in app.component.html file is app.component.html 文件中的代码是

<div class="app-header">
  <app-header></app-header>
</div>
<div class="main-container">
  <div class="content">
    <router-outlet></router-outlet>
  </div>
</div>

The code in app.component.scss file is app.component.scss 文件中的代码是

.app-header {
   min-width: 750px;
}

.main-container {
   min-height: 100vh;
   min-width: 600px;
   background-color: #f7f7f7;
   padding: 0px 75px 50px;
   .content {
      margin: 0 auto;
      max-width: 800px;
      min-width: 600px;
   }
}

The code in the header.component.html ie app-header which is used in app-component is header.component.html 中的代码即 app-header 中使用的 app-component 是

<div class="header">
   <mat-toolbar>
   </mat-toolbar>
</div>

The code in header.component.scss is header.component.scss 中的代码是

.header {
    .mat-toolbar {
        background: lightgreen;
        color: #FFFFFF;
    }
}

The reason I am following above approach is for my content inside the div with.content class to have minimum width of 600px and maximum width of 800px.我遵循上述方法的原因是我在 div 中的内容 with.content class 的最小宽度为 600 像素,最大宽度为 800 像素。 This approach looks okay for desktop but for smaller devices the div with.main-container class doesn't occupy full viewport height as shown below.这种方法在桌面上看起来不错,但对于较小的设备,带有.main-container class 的 div 不会占据整个视口高度,如下所示。

在此处输入图像描述

Also I want header to occupy full screen width by setting width in percentage or viewport width like 100vw rather than using min-width: 750px.我还希望 header 通过设置百分比宽度或视口宽度(如 100vw)而不是使用 min-width: 750px 来占据全屏宽度。 Even for.main-container div I added min-width: 600px and would like to replace it with 100vw or something similar.即使 for.main-container div 我添加了 min-width: 600px 并想用 100vw 或类似的东西替换它。 I want it to occupy full screen width irrespective of device.无论设备如何,我都希望它占据全屏宽度。 I tried but couldn't achieve the results I wanted.我尝试了但无法达到我想要的结果。 Please help me fix these issues.请帮我解决这些问题。

I think the first thing you want to rule out is a missing viewport meta tag in the header of your page.我认为您要排除的第一件事是页面的 header 中缺少视口元标记。

Make sure you have a meta tag similar to this in the page header确保您在页面 header 中有与此类似的元标记

<meta name="viewport" content="width=device-width, initial-scale=1">

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM