Home > Net >  CSS Layout Noob
CSS Layout Noob

Time:10-23

Hi I feel dumb for asking the following but im at a loss. I am trying to create the following layout for a website but have not been able to create exactly what I want. I know it should be very simple to do but I'm a developer not a UI / UX wizard. Site Layout

So im looking to have a side bar on the left with menu items, a top nav (fixed to the top of the page) and a footer fixed to the bottom of the page with the main body of the site scrolling within the area left between the top nav and footer. There are also pages where I would like the content in the main body to be vertically and horizontally aligned (form input)

Ideally im looking to use bootstrap 5.2 but am not against using css grids or whatever magical methods there may be to get to what im looking to do. I'm also looking to try and make this all responsive hence starting to use Bootstrap I didn't want to have to implement my own media queries to do it.

Thanks in advance for any help or suggestions, I have been hitting my head against a brick wall with this for far too long and thought I would reach out and see if anyone was able to help.

CodePudding user response:

You have two distinct columns, (1) sidebar and (2) everything else.

Within the main row, we can form the two columns: col-2 and col-10, with the first acting as our sidebar and the other acting as our main column.

In the main column, we add a row and then add to it the nav, main content and footers.

    <div >
        <div >
            <div >
                sidebar
            </div>
            <div >
                <div >
                    <div >
                        nav
                    </div>
                    <div >
                        <p>1</p>
                        <div style="height: 5000px;">a</div>
                        <p>2</p>
                    </div>
                    <div >
                        footer
                    </div>
                </div>
            </div>
        </div>
    </div>

In the CSS we set the height for the nav and footer, and then use calc() to measure the height our main content should be and set the overflow to scroll to get the scrollbar if the content is larger than the height.

        .nav {
            height: 60px;
        }

        .main {
            height: calc(100vh - 120px);
            background: #f1f1f1;
            overflow: scroll;
        }

        .footer {
            height: 60px;
        }
  • Related