1
我試圖將div
元素的高度設置爲屏幕高度減去固定數量的像素。將元素的高度設置爲屏幕高度 - Angular2
我正在構建一個帶有角度的單頁應用程序,現在它處於初期階段。該頁面目前由一個固定24像素高度的單個標題欄組成。
直接位於此標題下方的是<app-root></app-root>
組件,該組件由角度自動生成,其中包含一個div,<div id="work-area"><div>
。
我想要做的就是將這個#work-area
div從標題底部延伸到屏幕底部,如果要在純JavaScript中完成,則需要screen.height - 24px
。
我不知道如何去做這件事。我到目前爲止嘗試了幾件事:
- 將腳本嵌入到包含JavaScript代碼的角度HTML模板中以設置寬度。這不起作用,因爲角度不支持嵌入的腳本標記。
- 我試着使用純CSS設置高度,我無法得到這個工作,我很確定純CSS不會完成這個目標,但如果它確實,它將是首選的方法。
- 最後我看了一下
ngStyle
屬性指令,但是這隻需要純CSS而不是javascript,所以我遇到了和上面相同的問題。
下面是我的文件櫃面它使問題更加清晰:
//app-root component
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: '<div id="work-area"></div>',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
}
的index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WorkspacePrototype</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<div class="overflowing-bar">
<div id="header">
</div>
</div>
<app-root>Loading...</app-root>
</body>
</html>
全球styles.css的
body, html {
width: 100vw;
height: 100vh;
margin: 0;
padding: 0;
}
.overflowing-bar {
overflow: hidden;
}
#header/*, #footer*/ {
width: inherit;
height: 24px;
margin: 0 auto;
background-color: blue;
}
這個工作!謝謝! – JavascriptLoser