Loading...
 
Skip to main content
New in Tiki 25: tiki-pagetop_colors.scss and Tiki CSS variables (CSS custom properties)
(Cached)

Pagetop Styles and CSS Variables

Motivation for these changes: Find a better way to style Tiki's mix of top/topbar elements and often nested navbars.

The arrangement of Tiki's navbars

The standard Bootstrap navbar element is normally a single navbar and isn't used in combination with another one. On the other hand, Tiki's top and topbar elements evolved from pre-Bootstrap portal-style layouts. The way Bootstrap is implemented in Tiki's page-top elements often puts one navbar element inside another — one for the entire module zone, and often one for a menu contained in a module in that module zone. If both navbars, the outer and inner one, have solid-color backgrounds, and it's the same color, then there's no problem with appearance. But if a gradient or image is specified for the background, then the navbar-on-navbar effect is obvious and usually unattractive.

Even if there were just one navbar, but it was contained in one or more divs that have content in addition to the navbar, there would still be a styling problem to deal with, involving color consistency, borders, shadows, and so on, this area.

Some time ago, the parent divs of a navbar in the top module zone were given CSS classes such as bg-light-parent or bg-dark-parent . When the color preference of the navbar is switched in Look & Feel Admin, the colors of these parent divs are also switched, along with the colors of the navbar they contain, with the thinking that this is the desired behavior to prevent a patchwork of colors in these zones. (Of course this can be overridden by custom CSS or a theme stylesheet if desired.) That was one step to coordinate pagetop color styling.

The basic idea of tiki-pagetop_colors.scss

Assuming the navbar's parent divs and the navbar have the same color scheme, to prevent "gradient-on-gradient" or "bordered box or box-shadowed box inside bordered box or box-shadowed box," with tiki-pagetop_colors.scss , the styling is applied only to the topmost or outermost element, such as .navbar.fixed-top in the Basic Bootstrap layout, and then any nested div.bg-*-parent and the navbar itself is give a transparent background and borders and box-shadows are given a none value.

A caveat here: The assumption with this discussion is that a common background color or treatment is wanted for the entire top module zone or topbar module zone. In the case of a design where the module zone has one background color or gradient or image and a menu in that module zone has a different one, then theme designer shouldn't import themes/base_files/scss/tiki-pagetop_colors . The purpose of the file is to make uniform the background and foreground colors of the relevant divs and enable easy modification of these properties.

I found myself repeatedly writing a lot of CSS to style these page elements, especially when linear gradients or images are used for backgrounds. [Show example code.] I asked myself why do I need to do this for every theme with this type of color scheme? Not only aftermarket or custom themes but also some in the Tiki package like Darkroom and FiveAlive, and some Bootswatch themes like Cerulean have potential "gradient on gradient" problems if special CSS isn't written to counteract it.

First step: tiki-pagetop_colors

I had earlier created an SCSS file for color-variant child themes like those in FiveAlive and FiveAlive-lite, to avoid having to write the same CSS color rules for each theme. I used the same idea for the pagetop colors file that could be used by any theme, and the color-variant child themes could also use this file.

I made the file by collecting the "tiki-selectors" SCSS rules of themes that have relatively complex top and topbar zone color styles, and then simplified the rules, eliminating redundancies, and so on; initially this was just for background colors but then it was extended to cover background gradients and background images also. It addresses both top and topbar module zones (and parent divs) and both dark and light navbar options. (As of Bootstrap 5.2, the navbar-light and bg-light classes are retired, but are still used in Tiki unless there is a good reason to change.)

Pagetop styles and CSS variables

As the tiki-pagetop_colors file was progressing, SCSS variables were used to set values for the properties, as with most of Tiki's theme files. But it was apparent that this would be a natural and very useful place to use CSS variables, which to be honest I was just starting to get a handle on, so this was really a learning experience for me. So I replaced the SCSS variables in this file with CSS variable equivalents, and found the location in the theme files to define the CSS variables. This was tested first with the Utopias theme and since then I'm working my way through the other themes.

Example of CSS variable use in themes/base_files/_tiki-pagetop_colors.scss:

Copy to clipboard
// Topbar module zone and parent divs - dark color .layout_basic .topbar_modules.bg-dark, // Single Container layout -- Topbar, which probably includes another nav menu .layout_classic .topbar.bg-dark-parent, // Classic Tiki layout -- Parent of the topbar module zone .layout_social .topbar-wrapper.navbar-dark-parent.bg-dark-parent // Classic Bootstrap topbar wrapper { background: var(--tiki-topbar-bg-dark) !important; color: var(--tiki-topbar-dark-color); a:not(.dropdown-item), .btn.btn-link { color: var(--tiki-topbar-dark-link-color); &:hover { color: var(--tiki-topbar-dark-link-hover-color); } } }


Included page CSS Variables in Tiki:

Background info on CSS variables

Custom properties (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that contain specific values to be reused throughout a document. They are set using custom property notation (e.g., --main-color: black;) and are accessed using the var() function (e.g., color: var(--main-color); ).
-- https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties

See also: https://css-tricks.com/a-complete-guide-to-custom-properties/

CSS variables in Bootstrap

There were just 28 CSS variables in Bootstrap 4 (https://getbootstrap.com/docs/4.0/getting-started/theming/#css-variables). As of Bootstrap 5.2, this number, for root CSS variables, is up to approximately 70 (https://getbootstrap.com/docs/5.2/customize/css-variables/#root-variables). Root CSS variables have global scope. There are also component variables, with narrow scope, such as those used for tables and navbars, and as shown below in the examples of the top and topbar zone CSS variables.

The Tiki CSS variable syntax

To distinguish SCSS variables created specifically for Tiki from Bootstrap or other SCSS variables, they have a $tiki- prefix (implementation of this is a work in progress). The same pattern is used for Tiki's CSS variables, with --tiki- . (The prepended two hyphens are the standard notation for CSS variables.)

CSS variables currently used by Tiki

Top and topbar module zones (navbars)


For Tiki 26, the CSS variables used for the top and topbar module zones (navbars) have been reorganized. Instead of CSS variables with specific color ("light" or "dark") names, in Tiki 26 the variable names don't mention color themselves. Instead, neutral-color names are used in each combination of color and location — 1) light / top, 2) light / topbar, 3) dark / top, and 4) dark / topbar. This will facilitate using them with whole-website color mode switching in Tiki 26, which uses Bootstrap 5.3.

Selector (Bold) and Variable Name Description
.tiki-top-nav-light { Top module zone, light option (set in Look and Feel admin)
.tiki-top-nav-dark { Top module zone, dark option (set in Look and Feel admin)
--tiki-top-bg Top module zone background color (CSS color, gradient, image, etc.)
--tiki-top-color Links in top module zone
--tiki-top-hover-color Hover color for "
--tiki-top-hover-bg Color of link background during pointer hover
Link active color isn't implemented . . . . . . but can be if requested.
Link active background isn't implemented . . . . . . but can be if requested.
--tiki-top-text-color Applies to text such as log-in form labels in header mode (added for Tiki 26.1).
--tiki-top-border Style and color of border on the top zone, such as solid black
--tiki-top-border-width Width of border on the top zone, such as 2px
--tiki-top-box-shadow Box shadow on the top zone, such as 0px 2px 5px grey . Note that "0" requires a unit (px, etc.) in a CSS variable. Also, normally there is no space around the top navbar so a shadow is not likely to be visible unless spacing is configured for it.
}
.tiki-topbar-nav-light { Topbar module zone, light option (set in Look and Feel admin)
.tiki-topbar-nav-dark { Topbar module zone, light option (set in Look and Feel admin)
--tiki-topbar-bg Topbar background color (CSS color, gradient, image, etc.)
--tiki-topbar-color Color of text, etc. other than links. This is available but not currently used. Covers only immediate child elements.
--tiki-topbar-hover-color Hover color for "
Link active color isn't implemented . . . . . . but can be if requested.
--tiki-topbar-hover-bg Color of link background during pointer hover
Link active background color isn't implemented . . . . . . but can be if requested.
--tiki-topbar-text-color Applies to text such as log-in form labels in header mode (added for Tiki 26.1).
--tiki-topbar-border Style and color of border on the topbar zone, such as solid black
--tiki-topbar-border-width Width of border on the top zone, such as 2px
--tiki-topbar-box-shadow Box shadow on the top zone, such as 0px 2px 5px grey . Note that "0" requires a unit (px, etc.) in a CSS variable. Also, a shadow may not be visible unless spacing is configured for it.
}

Site Title and Subtitle (Logo module)

Selector (Bold) and Variable Name Description
:root { Use ":root" for global application (all layouts and pages, etc.)
--tiki-site-title-font-size Font size and weight (this row and below) for the logo module in the Classic Tiki and Single Container layouts. (These variables are used in themes/base_files/scss/_tiki-modules.scss.)
--tiki-site-title-font-weight
--tiki-site-subtitle-font-size
--tiki-site-subtitle-font-weight
--tiki-fixed-top-site-title-font-size Font size and weight (this row and below) for the logo module in the Classic Bootstrap (layout_social, fixed-top) layout (likely smaller than for the static position).
--tiki-fixed-top-site-title-font-weight
--tiki-fixed-top-site-subtitle-font-size
--tiki-fixed-top-site-subtitle-font-weight
--tiki-site-title-color (These variables are used in an inline style in templates/modules/mod-logo.tpl.)
--tiki-site-subtitle-color
}

Unified Admin Backend

The variables below are used on the new (Unified Admin Backend) admin pages for the top and side navbars and menus. (The top navbar's background is specified separately with a different selector, below.*)

Selector (Bold) and Variable Name Description
.tiki .tiki-admin-top-nav-light,
.tiki .tiki-admin-aside-nav-light {
Selectors used by "Admin navbar background color" Light option
.tiki .tiki-admin-top-nav-dark,
.tiki .tiki-admin-aside-nav-dark {
Selectors used by "Admin navbar background color" Dark option
--tiki-admin-top-nav-color Link color (link labels and icons) in the top navbar
--tiki-admin-top-nav-hover-color Link color when pointer hovers, in the top navbar
--tiki-admin-top-nav-hover-bg Color of link background when pointer hovers
--tiki-admin-aside-nav-bg Background color of side-column menu. Normally specified by the theme to be the same as top navbar background color but, like all of these selectors, it can be overridden.
--tiki-admin-aside-nav-color Link color (text and icons) in the side menu
--tiki-admin-aside-nav-hover-color Link color when pointer hovers, in the side menu
--tiki-admin-dropdown-bg Background color of top navbar menu dropdowns, including the login module, etc., and of the side menu dropdown sections.
--tiki-admin-dropdown-link-color Link color (link labels and icons) in the menu dropdowns
--tiki-admin-dropdown-link-hover-color Link label and icon color when pointer hovers, in the menu dropdowns
--tiki-admin-dropdown-link-hover-bg Link background color when pointer hovers, in the menu dropdowns
}
.tiki.tiki-admin .top_modules.navbar-light-parent { Selector used by "Admin navbar background color" Light option
.tiki.tiki-admin .top_modules.navbar-dark-parent { Selectos used by "Admin navbar background color" Dark option
--tiki-admin-top-nav-bg Background color of the top navbar
}

Miscellaneous

Selector (Bold) and Variable Name Description
:root { Applies globally.
--tiki-page-content-top-margin To create white space at the top of the content area, below the site header, input code just like this in the Look & Feel admin CSS Customization form, with a pixel, em, or rem size. Example: :root { --tiki-page-content-top-margin: 15px; }. Other global CSS variables can also be placed in this array (between the curly braces).
}

Selector and Variable Name Notes
:root {
--tiki-top-bg-light
--tiki-top-light-color
--tiki-top-light-link-color
--tiki-top-light-link-hover-color
--tiki-top-light-link-hover-bg
--tiki-top-light-box-shadow
--tiki-topbar-bg-light
--tiki-topbar-light-color
--tiki-topbar-light-link-color
--tiki-topbar-light-link-hover-color
--tiki-topbar-light-link-hover-bg
--tiki-topbar-light-box-shadow
--tiki-topbar-light-border
--tiki-topbar-border-width for light and dark topbars
--tiki-top-bg-dark
--tiki-top-dark-color
--tiki-top-dark-link-color
--tiki-top-dark-link-hover-color
--tiki-top-dark-link-hover-bg
--tiki-top-dark-box-shadow
--tiki-top-dark-border
--tiki-top-border-width
--tiki-topbar-bg-dark
--tiki-topbar-dark-color
--tiki-topbar-dark-link-color
--tiki-topbar-dark-link-hover-color
--tiki-topbar-dark-link-hover-bg
--tiki-topbar-dark-box-shadow
--tiki-topbar-dark-border
--tiki-static-top-light-border this and the following, for Classic Tiki and Single Container layouts
--tiki-static-top-dark-border
}
header.navbar.fixed-top { These are very explicit because they are used in the calculation of the site logo image; their scope is limited to header.fixed-top.
--tiki-fixed-top-border-top-width
--tiki-fixed-top-border-right-width
--tiki-fixed-top-border-bottom-width
--tiki-fixed-top-border-left-width
--tiki-top-light-border-color
--tiki-top-dark-border-color
}


Related, there are also these CSS variables for the site title and subtitle, in fixed-top position (Basic Bootstrap layout) and static position (Classic Tiki and Single Container layouts) and their default values:

    --tiki-fixed-top-site-title-font-size: 1.8rem;          // Fixed-top position (Basic Bootstrap layout)
    --tiki-fixed-top-site-title-font-weight: 700;
    --tiki-fixed-top-site-subtitle-font-size: 1.4rem;
    --tiki-fixed-top-site-subtitle-font-weight: 400;

    --tiki-site-title-font-size: 2rem;                      // Static position (Classic Tiki and Single Container layouts)
    --tiki-site-title-font-weight: 700;
    --tiki-site-subtitle-font-size: 1.5rem;
    --tiki-site-subtitle-font-weight: 400; 


-

Theme-specific CSS variables

CSS variables are used by some Tiki themes already for color mode compliance or for situations where site admins might want to configure the theme's appearance or behavior in a particular way.

Background image path

A CSS variable can represent the path to an image file used for the background of some page element, like this:

From the Feb12 theme's _tiki-selectors.scss file
Copy to clipboard
.middle { background: var(--tiki-feb12-middle-bg); padding-bottom: 20px; }


Then --tiki-feb12-middle-bg is specified differently, to fetch different files, or one file or no file, depending on whether light or dark color mode is being used:

From the Feb12 theme's _css-variables.scss file
Copy to clipboard
:root { --tiki-feb12-middle-bg: #ffffff url(../images/page.jpg) repeat-x; } [data-bs-theme="dark"] { --tiki-feb12-middle-bg: transparent;

Defining CSS variables

As the docs on CSS variables show, they are placed in one or more arrays, each headed by a selector. These arrays, for a theme, are usually in the theme's _css-variables.scss file, or they can be placed at the end of the theme's _variables.scss file. This positions the arrays after the SCSS variables are defined, which CSS variables may require.

Using Look & Feel CSS Customization

To redefine one or more of the CSS variables, the variable name and the new value for it can be input in the Look & Feel admin customization text area, inside the :root array or under another appropriate selector, as indicated in the tables above. This could also be in a custom.css file.

Future possibilities

  • A dedicated Look & Feel "CSS Variables" text area provided so that just the variables could be entered and the root array syntax would be added on the backend.
  • New Tiki CSS variables in addition to those listed above — what other Tiki page elements should easy customization be enabled for?
  • Site color controls (or other controls) available to site users on the public side, such as for dark mode, like switching themes but not needed a page refresh. — This is implemented in Bootstrap 5.3 and will be in the upcoming Tiki 26 release.

References:


Page last modified on Thursday 02 of February, 2023 15:28:03 GMT-0000