Search code examples
htmlcssfixed

Display CSS: some divs fixed, some flexible


I need the following to happen in my website: The counter and logo (top, bottom) should always have the same height and stay on the top and bottom even though the screen height will decrease/increase. BUT the 2 other divs in between should get smaller/bigger when the window changes. I hope with this example its easier to understand:

pic

The logo will disappear when the screen height is too low, right now. Here is the css:

The section is 80% width and aside 20%, but that doesnt really matter here...

#countdown{
padding: 0.5em 0.5em 0.5em 3em;
margin: 0.5em;}

#addProject{
margin: 0.5em;
padding: 0 1em;
height: 44%;
overflow-y: auto;}

#Nye{
margin: 0.5em;
padding: 0 1em;
overflow-y: auto;
height: 40%;
}

#logo{
margin: 1em;
height: 5em; 
}

Solution

  • @Rémi offered a good start, but I would recommend using position: fixed.

    This will anchor your elements to the browser window, regardless of the amount of your content.

    e.g.:

    .counter, .middle1, .middle2, .logo {
        position: fixed;
        width: 20%;
        min-width: 200px;
        right:0;
    }
    .counter {
        background: yellow;
        top:0;
        height: 50px;
    }
    .middle1 {
        overflow: scroll;
        background: blue;
        top:50px;
        bottom: 50%;
    }
    .middle2 {
        overflow: scroll;
        background: green;
        top: 50%;
        bottom:50px;
    }
    .logo {
        background: pink;
        bottom:0;
        height: 50px;
    }
    

    See http://jsfiddle.net/uKPEn/1/