Navbars

Blox Project Table of Contents | Overview of all Projects

Inhaltsverzeichnis des Blox-Projektes | Übersicht aller Projekte

Downloads of the Blox Project | Downloads of the entire Site | Imprint

Contents of this Page

  • 1   Aim
  • 2   docutils Containers
  • 3   Navbars with Multiple Sections
    • 3.1   The flexnavbar Container
    • 3.2   The Groups of the Navbar
  • 4   Navbars with Exactly One Section
  • 5   Footers
  • 6   Summary
  • 7   Discussion

1   Aim

The aim is the creation of a navigation bar with several sections, each containing e.g. a series of links. Typically there are two such sections, which shall be shown at the left and right end of the navigation bar. It shall however also be possible to show such a section only at the left end or only at the right end.

The single sections (or groups) of the navigation bar shall be written as paragraphs separated by empty lines in the content of a ReST container. For example, one shall be able to write:

.. container:: flexnavbar

    ((left link group))

    ((right link group))

Additionally, footers shall be made available in a similar way:

.. container:: flexfooter

    ((left link group))

    ((right link group))

The navigation bars of this kind are also called for short navbars.

2   docutils Containers

The docutils container directive encloses its content in the HTML rendering by a div element. One writes:

.. container:: ((arguments))

    ((body of the container))

The (optional) arguments of the container directive are translated into class names of the resulting div element.

When the body of the docutils container contains several paragraphs separated by empty lines, then these paragraphs are shown by docutils as p elements. Otherwise, when there is exactly one paragraph, the enclosing by a p element is omitted.

This has implications for the design of the navbar styles, because one cannot expect a p element in case there is only one section. Otherwise, when several paragraphs are present, the p elements can be used for styling.

docutils offers the compound directive to group contents into paragraphs. Thus, one can write:

.. container::

    .. compound::

        ((paragraph content))

Unfortunately, even though the compound directive creates a p element surrounding the ((paragraph content)) as intended, this paragraph however is not placed directly in the container div element. Instead, the p paragraph is embraced by an additional div element in the superordinate div container.

No method is known to me, to enclose in a container with only one paragraph as body its content in a p element, such that this paragraph is positioned directly in the container div element. Thus, separate styles are created for navigation bars with several sections and for such with only one section. Such a distinction is also required because for navigation bars with only one group it must be chosen between rendering this group on the left or right side. Furthermore, it is correct that docutils leaves out the p element when no multiple paragraphs are present, in order to keep the HTML rendering as simple as possible.

3   Navbars with Multiple Sections

The CSS code shown here is applicable for ReST texts of the following form:

.. container:: flexnavbar

    ((section 1))

    ((section 2))

    ((...))

It is required here that at least two sections ((section 1)) and ((section 2)) are present.

3.1   The flexnavbar Container

We give the div.flexnavbar the following style:

div.flexnavbar {
    display: flex;
    justify-content: space-between;
    background-color: #f8f8f8;

    border: thin solid #ddd;
    border-radius: 1.5ex;
}

By the declaration display: flex the div.flexnavbar element turns into a flex container with principal axis from left to right (this is the standard behaviour).

To show in the case of two sections ((section 1)) and ((section 2)) these sections at the left and right ends of the container, the declaration justify-content: space-between is applied.

Furthermore, we give to the entire navigation bar a grey colour tone, with a thin grey border line as well as rounded corners.

3.2   The Groups of the Navbar

Because several sections are present here in the body of the flexnavbar container, these are rendered as p elements. To format these sections of the navbar, one can write:

div.flexnavbar > p {
    text-align: left;
    padding: 0.5ex 0.8ex;
    margin: 1.25ex 1.5ex;
    background-color: white;

    border: thin solid #ccc;
    border-radius: 1ex;
}

Here those paragraph elements are selected, which are direct children of the container div.flexnavbar element. We frame the corresponding groups with a thin grey line by setting the border property. In the interior of the frame the groups are picked out by white background (background-color: white) from the navbar.

The corners of the lines surrounding the groups are rounded similarly to those of the navbar. In the exterior of the frames around each group some space is left to the border of the navbar (margin). The distance is intentionally horizontally a little larger than vertically.

The frame of a group is furthermore distanced a little bit from its text content (padding). Here, the horizontal distance is chosen slightly larger than the vertical distance, to render these distances visually equal. This is in particular required as a correction due to the rounded corners.

When in a section no line break is required, its horizontal size is determined precisely by its contained text:

Left Link

Right Link

When the horizontal room in a navigation bar is not sufficient to show the text of the navbar groups single-lined, the text-align: left declaration comes into effect:

Project Table of Contents | Overview of all Projects | Additional Link 1 | Additional Link 2 | Inhaltsverzeichnis des Projektes | Übersicht aller Projekte | Zusätzlicher Link 1 | Zusätzlicher Link 2

Downloads of the Project | Downloads of the Entire Site | Imprint

The surplus room is collected here by text-align: left at the right end of the section.

4   Navbars with Exactly One Section

In the case of a singleton group in the container for the navigation bar, no subordinate XML element exists to surround the content of the group. It is therefore impossible to graphically set off the single group from the surrounding navigation bar. Thus, it offers itself for the design:

div.flexnavbar-left {
    text-align: left;
    padding: 0.5ex 0.8ex;
    background-color: #f8f8f8;

    border: thin solid #ddd;
    border-radius: 1ex;
}
div.flexnavbar-right {
    text-align: right;
    padding: 0.5ex 0.8ex;
    background-color: #f8f8f8;

    border: thin solid #ddd;
    border-radius: 1ex;
}

These CSS codes raise the group to the navbar. The typesetting is largely equivalent to the design of the paragraphs in case of multi-sectioned navigation bars, but it pertains here to the div region instead of to the p elements, while the grey background of the div element is maintained. Because of this, the single group of the flexnavbar-left or flexnavbar-right navbar stretches over the entire breadth available. The contained text is formatted in the navigation bar left-justified or right-justified, respectively.

For instance, a navigation bar flushed left with a single region using flexnavbar-left is displayed as:

First Link | Second Link

5   Footers

Footers are populated with contents just as navigation bars, only a different CSS class is used for the surrounding container:

.. container:: flexfooter

    ((left section))

    ((right section))

No styles for footers with only one section are defined, because they aren't needed. There is always a group present on the left side with figures regarding the release date and a group on the right side to navigate in the publication history.

It is more simple to design footers than navigation bars, because footers are separated from the page contents already by a horizontal rule and are graphically in the background. Therefore it suffices to write:

div.flexfooter {
    display: flex;
    justify-content: space-between;
}
div.flexfooter > p {
    text-align: left;
    margin-top: 0pt;
    margin-bottom: 0pt;
}

Neither background colours nor borders are tailored. The principal approach is very similar to those for navigation bars with several entries: A flex-Container with justify-content: space-between is employed. For the p sections it suffices here to set the margin-top and margin-button figures to 0pt, overridding the docutils style of 1em.

An example is not given here, because the horizontal rule separating the footer from the text body of the page cannot be reproduced here and moreover it is essential for the rendering, that there is no further content following below the footer.

6   Summary

The CSS code for navigation bars with multiple groups, for navigation bars with only one group as well as for footers thus runs altogether:

navbars.css
div.flexnavbar {
    display: flex;
    justify-content: space-between;
    background-color: #f8f8f8;

    border: thin solid #ddd;
    border-radius: 1.5ex;
}
div.flexnavbar > p {
    text-align: left;
    padding: 0.5ex 0.8ex;
    margin: 1.25ex 1.5ex;
    background-color: white;

    border: thin solid #ccc;
    border-radius: 1ex;
}

div.flexnavbar-left {
    text-align: left;
    padding: 0.5ex 0.8ex;
    background-color: #f8f8f8;

    border: thin solid #ddd;
    border-radius: 1ex;
}
div.flexnavbar-right {
    text-align: right;
    padding: 0.5ex 0.8ex;
    background-color: #f8f8f8;

    border: thin solid #ddd;
    border-radius: 1ex;
}

div.flexfooter {
    display: flex;
    justify-content: space-between;
}
div.flexfooter > p {
    text-align: left;
    margin-top: 0pt;
    margin-bottom: 0pt;
}

7   Discussion

There are several design elements which can be seen in relation to the navbar: large buttons and code segments. The styles conceptualised here are defined in such a way, that the resulting navbars harmonise in design with these other elements. Thus, the radius of the outer corner rounding has been chosen identically as for the large buttons. The shade of grey of the navigation bars has been chosen in such a way, that the weight of the navigation bars is neither too large nor to small; this results in a grey different from the one used for code segments. The horizontal distance between the frames of the navbar groups and the edges of the navbar itself has been adjusted such that the result resembles the horizontal distances in the large buttons; the vertical distance is independent of these and has been set slightly smaller. An equalisation of the roundings of code segments and of navbars has been dispensed of, so that the sharp corners of the code segments remain unaltered.

Picking out graphically the groups of the navigation bar from the the navigation bar background emphasises that the elements of the group belong together. This is beneficial for clarity, when groups of a navigation bar are required to be shown multi-lined due to lack of space. Experience shows that for footers such an emphasis is not needed.

In case of multi-lined groups the sections of the navbar are broader than the wrapped content. The readability is optimum with text-align: left, this is here especially superiour to the text-align: justify alternative.


There is a newer version of this page available.

Released 27 June 2024. Decommissioned 7 January 2025.

← Previous Version | Next Version → | Latest Version