Reputation: 41
What i am trying to achieve is, that div 1 and 3 should keep their height, while div 2 should adjust to the height of the container.
A solution, which works on all the major mobile browsers would be great.
Upvotes: 0
Views: 116
Reputation: 21675
flexbox
is a great option for this and all you have to do is set flex-grow: 1
to the element that needs to be dynamic an fill the remaining space.
section {
display: flex;
flex-direction: column;
height: 400px;
}
header,
footer {
min-height: 75px;
}
header {
background-color: gold;
}
main {
flex-grow: 1;
background-color: skyblue;
}
footer {
background-color: indianred;
}
<section class="container">
<header>1</header>
<main>2</main>
<footer>3</footer>
</section>
* {
box-sizing: border-box;
}
body {
margin: 0;
display: flex;
flex-direction: column;
min-height: 100vh;
}
header,
footer {
min-height: 75px;
}
header {
background-color: gold;
}
main {
flex-grow: 1;
background-color: skyblue;
}
footer {
background-color: indianred;
}
<header>1</header>
<main>2</main>
<footer>3</footer>
Upvotes: 1