Bootstrap Navbar Centered Vertical Alignment

Recently I was working on a website layout using Bootstrap for which the design called for a large logo image as the navbar brand, with the navbar entries vertically centered with it. I thought “Yo, that’s crazy, there’ll be a lot of dead space in the navbar,” but the designer just said “Yo, I am crazy, do it.”

There’s many StackOverflow questions and blog posts on vertically aligning a Bootstrap navbar, but most of them don’t really work. Worse, all of the working solutions I found involved manipulating the line height of the entries. Unfortunately, that also fails with an additional crazy designer requirement: The navbar entries might be multi-line, so playing games with line-height thus wouldn’t arrange each entry’s text correctly. Eventually I was able to work out the details of another approach using table-cell, shown in this post. As is typical with HTML/CSS, especially with Bootstrap thrown in, and double especially regarding vertical alignment, the actual code is really short and seems obvious, but is much less so when trying to work out the magical incantation from scratch.

This demonstration is built on a Bootstrap’s Starter Templates, showing a navbar fixed to the top of the screen. I’ve just switched the navbar from navbar-inverse to navbar-default to use the lighter color scheme and added dummy text:

step00Note that the basic Bootstrap styling does not by default work with the fixed top, it obscures the page title. This is fixed in the last step of this demo.

Next I change the brand (“Project Name” in the template) to a large logo image and made one of the menu entries multi-line by fixing the width of the entries. The logo especially doesn’t work out well:

step01

Adjusting the Bootstrap navbar’s height requires adjusting the height of both the navbar and navbar-header class entries. The latter is used when the navbar is collapsed for small screens, to start the nav menu rolldown at the right place. Bootstrap’s default navbar brand top and bottom padding is 15px, so for my logo I increase the minimum height to 202px, 30px more than its height:

.navbar        { min-height: 202px; }
.navbar-header { min-height: 202px; }

step02

Moving on to the actual objective here, the first step is to vertically align the navbar entries among themselves along their middles. The easiest, most elegant way to do this is to change their display style to table-cell, which respects the vertical-align: middle property. There are two gotchas to this: The parent list must be set to display: table-row mode, and, more obscurely but sensibly in retrospect, the cells cannot be floats. Note that, unlike a few comments I did find, the parent container does not need to be in mode display: table. Thus:

      #navbar > ul {
      display: table-row;
      }
      
      #navbar > ul > li {
      display: table-cell;
      float: none;
      vertical-align: middle;
      }

step04

At this point the whole navbar line just needs to be shifted downward to center it with the logo. There is probably some convoluted mechanism or arcane invocation to do this automatically, but I’ve just been doing it by hand. To keep calculations simple I first add the padding to the navbar, and then shift the row down:

      #navbar {
      padding-top: 15px;
      }
      
      #navbar > ul {
      padding-top: 48px;
      }

step05
Note that for middle alignment it’s not necessary to set the height of the row, it just needs to be moved down by the padding.

After that the last tweaks are to center the cells and shift the page contents down below the heightened navbar:

      #navbar > ul > li {
      text-align: center;
      }

      body {
      margin-top: 202px;
      }

step06

Unfortunately this doesn’t really work well when the navbar collapses into the mobile navigation list dropdown:

step07

To address that, all of the above needs to be wrapped in a media query such that the stylings only take effect when the navbar is not collapsed. By default in Bootstrap this is when the window is at least 768px wide:

      @media (min-width: 768px) {

        #navbar {
        padding-top: 15px;
        }
      
        #navbar > ul {
        display: table-row;
        padding-top: 48px;
        }
      
        #navbar > ul > li {
        display: table-cell;
        float: none;
        vertical-align: middle;

        text-align: center;

        width: 80px;  /* crazy designer's fixed-width, multi-line entries */
        }
      }

step08

And with that, the objective of vertically centering multi-line entries with a large logo in a Bootstrap navbar is accomplished. #victory!

Mortalis Solypsus WIP

banner

Yesterday Colin and I got started on construction for the July PAGE/Redcap’s 40k event: Mortalis Solypsus. A bit over-ambitiously, we intend to run a full day of Zone Mortalis-styled games, capturing the fighting inside the Lab, Mine, and other installations of Solypsus 9. Note that the fluff here is that you’re fighting in huge facilities. Vehicles can fit through part of them, but may not be able to make it into narrower sections or rooms. Think NORAD, not office building.

Everybody should take note of the draft rules being collected on the event page. There are a number of restrictions and special rules to suit the indoor fighting. A basic restriction is that large vehicles are outright not permitted. Further, even permitted larger models like Dreadnoughts will not have full mobility throughout a board as they won’t fit through doorways and such. An example special rule is that blasts and templates gain Shred, and only scatter and take effect within the confines of the walls.

Although there’s a long way to go, we wanted to post some notes and pictures for both players thinking about what armies to prepare, and for the other hobbyists building boards for the event to follow along. As the boards are being constructed by several people and using a variety of styles, they will definitely vary a bit. But this is roughly how most of them will work.

If you are committed to playing in the event, please sign up on the Doodle poll so we can plan appropriately.

Colin starts measuring out walls.

Colin starts measuring out walls.

Layout

The game boards will all be 4×4, to suit the 1000 point armies. They are made up of 2×2 or 1×1 tiles, to give some variety in laying out a board. Each tile has a fixed layout of walls making corridors, generally along an 8×8 or similar grid. This gives just enough room for small vehicles such as a Rhino to move through, but in a somewhat restricted way. With other models present or scatter terrain such as debris, containers, or consoles, it may be difficult to have them turn in place and such to head in a new direction.

Line of sight is very limited by the walls. A number of walls do have doorways, but they’re staggered such that even with all of them open there is no line of sight across the board. Indirect attacks are in general not permitted, see the rules for details. Close up shooting and assault will definitely be emphasized compared to a normal game.

One of Colin's 2x2 tiles.

One of Colin’s 2×2 tiles.

Doorways

The doorways on our canonical board design are 2 inches wide and tall. This means anything up to about a Space Marine Centurion can easily move them them. Dreadnoughts, monstrous creatures, and other large models simply won’t fit. Although the tile designs generate discourage fully enclosed spaces, it will certainly be possible for troopers to huddle up away from a bigger foe and force it to take a roundabout route to them and the objective they are defending for the corpse god and/or false idols.

It doesn’t matter for gameplay purposes because they’re treated as an infinite surface, but for building purposes, the walls should be 3 to 4 inches tall. Many models need at least a 3″ wall to look right. At 4″ though the walls start to feel pretty cavernous against infantry, which might be an appropriate look for some themes.

A Kingbreaker checks out his new digs.

A Kingbreaker checks out his new digs.

Burn It Down!

Again, take a look at the draft rules to see some of the changes and special effects. And, if you are committed to participating, please sign up on the Doodle poll so we know how many people to expect.

Two WIP tiles together.

Two WIP tiles together.