2017-04-18 68 views
0

我無法讓我的列表成爲全高。我的代碼更復雜的嵌套組件。但是我仍然可以使用這段代碼來複制它。這是一個龐然大物。 http://plnkr.co/edit/R0QgLz8cjyRHYOLf4uJW設置角度組件的全高

styles.css的

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

app.component.css

.container { 
height: 100%; 
background: black; 
color: white; 

list.component.css

.row { 
    display: flex; 
    flex-direction: row; 
} 
.list { 
    width: 33%; 
    height: 100%; 
    flex-direction: column; 
    display: flex; 
    border-right: groove white 1px; 
    border-top: groove white 1px; 
} 
.item { 
    width: auto; 
    height: 100%; 
    flex-direction: column; 
    display: flex; 
} 

list.component.html

<div class="contents"> 
    <button (click)="updateDocuments()">Update Document</button> 
    <div class="row"> 
    <div class="list"> 
     <div *ngFor="let document of documents; let i = index;"> 
     {{i + 1}}. {{document}} 
     </div> 
    </div> 
    <div class="item"> 
     this is an item 
    </div> 
    </div> 
</div> 

回答

1

我這來切換到工作高度100vh,並在列表和項目類中添加overflow-y:scroll css屬性。

http://plnkr.co/edit/R0QgLz8cjyRHYOLf4uJW

styles.css的

html, body { 
    min-height: 100vh; 
    height: auto; 
    margin: 0; 
} 

app.component.css

.container { 
height: 100vh; 
background: black; 
color: white; 

list.component.css

.row { 
    display: flex; 
    flex-direction: row; 
} 
.list { 
    width: 33%; 
    height: 100vh; 
    flex-direction: column; 
    display: flex; 
    border-right: groove white 1px; 
    border-top: groove white 1px; 
    overflow-y: scroll; 
} 
.item { 
    width: auto; 
    height: 100vh; 
    flex-direction: column; 
    display: flex; 
    overflow-y: scroll; 
} 

list.component.html

<div class="contents"> 
    <button (click)="updateDocuments()">Update Document</button> 
    <div class="row"> 
    <div class="list"> 
     <div *ngFor="let document of documents; let i = index;"> 
     {{i + 1}}. {{document}} 
     </div> 
    </div> 
    <div class="item"> 
     this is an item 
    </div> 
    </div> 
</div> 
0

使用position: fixed如果這是可以接受的:

.container { 
    position:fixed; 
    background: black; 
    color: white; 
    height: 100%; 
} 
+0

我希望這工作。如果我的列表比查看高度長,我無法滾動。 – mkteagle

+0

你只是溢出它? – unitario

+0

請參閱:http://plnkr.co/edit/54mG5kYrowh0ixAM6CUb?p=preview – unitario

0

嘗試在你的style.css

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

這可以使高度達到可視高度。但是如果我有一個動態列表,流暢而不總是相同的高度,這是行不通的。特別是如果我將一個邊框添加到列表中。 – mkteagle

2

嘗試寫這個CSS

.container{ 
    min-height:100vh; 
} 
+1

試着解釋'100vh'的含義,這個問題可能會解決問題,但並不能解釋發生了什麼,爲什麼。 – Adam

+1

我明白100vh是什麼意思。但是如果我加100vh,這隻會把它看成可見的高度。如果有什麼東西被推過去,那就不是 – mkteagle