I am currently working on designing a full-screen layout where the content adjusts based on the size of the footer.
body {
margin: 0;
padding: 0;
}
.layout {
height: 100vh;
display: flex;
flex-direction: column;
background-color: yellow;
}
.layout__content {
height: 100%;
align-self: stretch;
background-color: blue;
}
.content {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background-color: green;
}
.content__text {
background-color: white;
}
.footer {
height: 20vh;
background-color: red;
}
<div class='layout'>
<main class='layout__content'>
<div class='content'>
<text class='content__text'>Here be dragons</text>
</div>
</main>
<footer class='footer' />
</div>
If I change the height
value within .footer
, the content will fill the remaining space from the footer as intended. Everything is functioning correctly.
Now, I want to create another layout where if the combined height of the content and footer exceeds 100vh
, a scrollbar should appear. If it does not exceed this height, the display should remain similar to the previous layout.
body {
margin: 0;
padding: 0;
}
.layout {
min-height: 100vh;
display: flex;
flex-direction: column;
background-color: yellow;
}
.layout__content {
height: 100%;
align-self: stretch;
background-color: blue;
}
.content {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background-color: green;
}
.content__text {
height: 150vh;
background-color: white;
}
.footer {
height: 20vh;
background-color: red;
}
<div class='layout'>
<main class='layout__content'>
<div class='content'>
<text class='content__text'>Here be dragons</text>
</div>
</main>
<footer class='footer' />
</div>
In the example, the text had a length of 150vh
. The issue is that removing this value causes the content to collapse.
body {
margin: 0;
padding: 0;
}
.layout {
min-height: 100vh;
display: flex;
flex-direction: column;
background-color: yellow;
}
.layout__content {
height: 100%;
align-self: stretch;
background-color: blue;
}
.content {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background-color: green;
}
.content__text {
background-color: white;
}
.footer {
height: 20vh;
background-color: red;
}
<div class='layout'>
<main class='layout__content'>
<div class='content'>
<text class='content__text'>Here be dragons</text>
</div>
</main>
<footer class='footer' />
</div>
Notes:
- I aim to modify attributes only within
layout
andlayout__content
. - The
footer
can vary in height, making it challenging to hardcode values likeheight
,min-height
,max-height
, etc., into other elements. In the given example, it was set at20vh
, but this is just for illustration purposes.
I have attempted several solutions:
layout
-height: 1px;
layout-content
-min-height: inherit
;layout-content
-min-height: 100%
;
If you have any ideas or suggestions, please share them!