Skip to main content
Inspiring
December 16, 2022
Question

Trying to get the side bar background to extend to the bottom, using CSS

I’m trying to get the sidebar div, “col-2” to extend down to the bottom with the content in the adjacent column, “col”.  Col-2 contains a vertical navbar in a blue background. I’m trying to get the blue background to extend to the bottom of the page, matching the length of variable content on the right. I have tried all solutions I found on the internet. I’ve set the height to 100%. I have tried flex-grow and flex-shrink. I’ve tried changing the positioning, as well as using 100vh, 100vw settings. There was either no change, or it messed up the design. Is there any simple solution? I was hoping height: 100%; would work, but nothing is every that easy. 

 

Here is the relevant code:

 

*{padding: 0;

margin: 0;

box-sizing: border-box;

 

}

body {

margin-top: 4.2rem;

min-height: 100vh;

display: flex;

flex-direction: column;

height: 100%;

}

 

.main {

position: relative;

overflow: inherit;

display:flex;

width:95%;

}

 

/** vertical blue container wrapping navbar**/

.col-2 {

position: relative;

padding: 0 1rem 1rem .1rem;

    float: left;

min-height: 100%;

background-color: #27254F; 

}

 

/** adjacent column on the right, containing content..text, images, etc**/

col {padding: 0 1rem 2rem 2rem;

margin-top: .5rem;

margin-left: 10rem;

margin-right: 0.3rem;

height: 100%;

}

 

    This topic is closed to new replies. Start a new post to keep the conversation going.

    6 replies

    Nancy OShea
    Community Expert
    Community Expert
    December 16, 2022

    I think my solution from 2 days ago takes of it.

    Equal height colums are easily achieved with flexbox. And no part of your layout requires positioning of any kind.  😉

     

     

    Translate
    Nancy O'Shea— Product User & Community Expert
    Inspiring
    December 16, 2022

    The vertical navbar column  has a fixed height and the content column has a variable height (because it is a template for several pages). I set the height on both columns to 100%, with no luck. 

    Translate
    Legend
    December 16, 2022

    Just insert col and col-2 inside your main div container and set their widths as a percentage of the main div container.

     

    No need for any positioning or overflow on the main container div.

     

    No need for any positioning on col-2 or any float or min-height.

     

    No need for setting a height on col  as that will be determined by the content.

     

    Set css on the main container div:

     

    box-sizing: border-box;

     

    This will ensure the padding/margin you have applied to col and col-2 gets set as a part of the width of the columns rather than added to the width.

    Translate