Skip to content Skip to sidebar Skip to footer

Css Flexbox: Header, Main, Footer Layout. Main Part Collapsing In The Middle

I have a simplest situation with Whatever
&

Solution 1:

I don't know how you where trying to this method out, but it's working (now at least).

Here's a JSFiddle showing the layout - I added a subtle background-color to illustrate the stretch.

<header>header</header>
<main>main</main>
<footer>footer</footer>

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

body {
    display: flex;
    flex-direction: column;
}

header {
    height: 75px;
}

main {
    flex: auto;
    background-color: #ccc;
}

footer {
    height: 25px;
}

Solution 2:

In the end i.e. after your footer tag you can put this javascript code

<script>var header = document.getElementsByTagName("header")[0];
var main = document.getElementsByTagName("main")[0];
var footer = document.getElementsByTagName("footer")[0];

header.style.height=screen.height*0.15+"px";
main.style.height=screen.height*0.80+"px";
footer.style.height=screen.height*0.05+"px";    
</script>

Post a Comment for "Css Flexbox: Header, Main, Footer Layout. Main Part Collapsing In The Middle"