Hier ist 2 Spalten Markup mit display: table
und display: table-cell
CSS-Deklarationen:
.table {
display: table;
}
.cell {
border: 2px solid black;
vertical-align: top;
display: table-cell;
}
.container {
height: 100%;
border: 2px solid green;
}
<div class="table">
<div class="cell">
<p>Text
<p>Text
<p>Text
<p>Text
<p>Text
<p>Text
<p>Text
<p>Text
</div>
<div class="cell">
<div class="container">Text</div>
</div>
</div>
Aber .container
Block füllt die übergeordnete Zelle nicht vertikal. Hier ist ein Beispiel für JsFiddle: http://jsfiddle.net/MGRdP/2 .
Was ich habe | Was ich brauche
Bitte schlagen Sie keine JS-Lösung vor.
Wenn Sie %
Um Höhen oder Breiten einzustellen, stellen Sie immer auch die Breiten/Höhen der übergeordneten Elemente ein:
.table {
display: table;
height: 100%;
}
.cell {
border: 2px solid black;
vertical-align: top;
display: table-cell;
height: 100%;
}
.container {
height: 100%;
border: 2px solid green;
-moz-box-sizing: border-box;
}
<div class="table">
<div class="cell">
<p>Text
<p>Text
<p>Text
<p>Text
<p>Text
<p>Text
<p>Text
<p>Text
</div>
<div class="cell">
<div class="container">Text</div>
</div>
</div>
einstellen height: 100%;
und overflow:auto;
für div inside .cell
table{
height:1px;
}
table > td{
height:100%;
}
table > td > .inner{
height:100%;
}
Bestätigt arbeiten an:
Zusätzlich zu jsFiddle kann ich einen hässlichen Hack anbieten, wenn Sie möchten, um ihn browserübergreifend zu gestalten (IE11, Chrome, Firefox).
Anstatt height:100%;
, stellen height:1em;
auf der .cell
.
Das ist genau was Sie wollen:
HTML
<div class="table">
<div class="cell">
<p>Text</p>
<p>Text</p>
<p>Text</p>
<p>Text</p>
<p>Text</p>
<p>Text</p>
<p>Text</p>
<p>Text</p>
</div>
<div class="cell">
<div class="container">Text</div>
</div>
</div>
CSS
.table {
display: table;
height:auto;
}
.cell {
border: 2px solid black;
display:table-cell;
vertical-align:top;
}
.container {
height: 100%;
overflow:auto;
border: 2px solid green;
-moz-box-sizing: border-box;
}
Machen Sie die Position der Tabellenzelle relativ und machen Sie dann die innere Div-Position absolut, wobei oben/rechts/unten/links alles auf 0px gesetzt ist.
.table-cell {
display: table-cell;
position: relative;
}
.inner-div {
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
}
Definiere dein .table
und .cell
height:100%;
.table {
display: table;
height:100%;
}
.cell {
border: 1px solid black;
display: table-cell;
vertical-align:top;
height: 100%;
}
.container {
height: 100%;
border: 10px solid green;
}