A fixed navbar and sticky footer

It is nice to work with Bootstrap. CSS seems less intimidating and more approachable, and they also keep improving Bootstrap every year. However, there are developments in standard CSS which we tend to ignore because of the familiarity and convenience of Bootstrap. And some dev outfits might not want its developers to use Bootstrap, so it’s always a good practice to learn alternatives.

Let’s create a new project with a fixed navbar and a sticky footer using only CSS Grid.

On the command window, create a project named no_bs.

Stop the server if it is still running.

[00000000(----) INF] Received signal 2. Shutting down.
[main(----) INF] Stopped to listen for HTTP requests on ::1:8080
[main(----) INF] Stopped to listen for HTTP requests on 127.0.0.1^C:8080
Warning
: c:\vibeprojects\hello>3 socket handles leaked at driver shutdown.
Warning: 3 socket handles leaked at driver shutdown.
c:\vibeprojects\hello>cd ..
c:\vibeprojects>dub init no_bs -t vibe.d
Package recipe format (sdl/json) [json]:
Name [no_bs]:
Description [A simple vibe.d server application.]:
Author name [Owner]:
License [proprietary]:
Copyright string [Copyright © 2023, Owner]:
Add dependency (leave empty to skip) []:
     Success created empty project in c:\vibeprojects\no_bs
             Package successfully created in no_bs
c:\vibeprojects>cd no_bs
c:\vibeprojects\no_bs>

Open the no_bs folder in VS Code and edit source\app.d to make it look like this:

Next, create views\layout.dt:

Then create views\styles.dt:

Then create views\menu.dt:

Then create views\index.dt:

And make stub pages for views\about.dt:

and views\contact.dt:

and views\login.dt:

After you compile and run, you should be able to see these pages:

We just created a layout with a fixed navbar and a sticky footer without using Bootstrap. If you expand and contract the browser, you will see that the middle row expands and contracts to fit the page, making the pages responsive.

In the views\styles.dt file, we declared this:

We did not declare any columns, effectively making the whole page just one column with three rows. The menu bar is on the top row and the footer is on the bottom row, with the middle row expanding and contracting to fit the page height when the browser is resized, thus making it responsive.

With CSS Grid, you will notice that the layout terms are declared in the CSS file so the HTML file is cleaner compared to using Bootstrap.

Now let's add a modal dialogue to the menu without JavaScript.

Last updated