Community Documentation

How CSS works in Omega - "Ogres are like Onions... They have LAYERS"

Last updated February 27, 2013. Created by Cellar Door on October 4, 2011.
Edited by bisonbleu, jay-dee-ess, brylie, stieglitz. Log in to edit this page.

CSS is where Omega gains its power. Through CSS media queries, Omega has the ability to determine the width of the browser and respond accordingly. Understanding how this response happens is critical to creating a working responsive theme in Omega. All the css files you’ll want to focus on editing are found in your sub-themes css folder at sites/all/themes/yoursubthemename/css

NOTE: When the responsive grid is disabled, the “Primary Layout” is used. By default this is set to the “normal” width. In this case, using global.css and yoursubthemename-alpha-default-normal.css files will load and thus you will want to put your edits in one of these.

Know thy Layers

Learning how these various layers affect each other, you will begin to see how best to create your stylesheets to achieve the desired effect. The layers we will be discussing and their shorthand are as follows:

  • global.css = global
  • yoursubthemename-alpha-default.css = default
  • yoursubthemename-alpha-default-narrow.css = narrow
  • yoursubthemename-alpha-default-normal.css = normal
  • yoursubthemename-alpha-default-wide.css = wide

Inheritance is key

The best way to think of these layers is as transparent panes of glass, upon which you are creating your styles. What is placed on the bottommost layer will show through to the others unless an identical style is placed over the top of it on a higher layer. This inheritance of your style from one layer to the next will help prevent bloated css files that have duplicate styles on each layer.

Using the stacked glass illustration, global.css is your bottommost layer which if not overwritten will have its style inherited by all layers.

*NOTE* Omega is a “Mobile First” theme design. This means that the theme is built up from the mobile experience and progressively enhanced until the desktop version is shown. Mobile-first design will be the basis for the whole experience, and global.css will allow you to create a seamless responsive environment for your users.

Layer upon layer

The layer structure of the default responsive css files is (from bottom to top): global → default → narrow → normal → wide . As the media queries respond with the browser width, the css files are either stacked on or taken off in the order listed above. For example, a media query of normal will stack up global, then default, then narrow, and lastly normal. Thinking back to the layered glass illustration, the stacked css files will then layer on their style leaving the areas not overridden to show through. This layering effect allows you to make changes at each consecutive layer as the browser width increases while keeping uniformity in the site from inheritance. Keeping a good sense of what file you want to edit in order to achieve the desired effect will take some getting used to, but, in time, lean css code is possible with only the overridden values in each layer of styling.

Comments

File naming convention

One note on naming your files. The example above works great if your theme is named yoursubthemename. But if you've named your theme your_subtheme_name it won't work the same. You have to change your filename from your_subtheme_name-alpha-default.css to your-subtheme-name-alpha-default.css (notice underscores (_) turn into dashes (-).

----------------------------------------
Chuck Crandall
WebChuck Web Development
chuck at webchuckweb dot com
----------------------------------------

Inheritance documentation not accurate

When using a fresh install of Omega 3.x the documentation infers the 'wide layout' will inherit styles from the 'normal layout', this is not entirely accurate.

Whilst yoursubthemename-alpha-default.css and yoursubthemename-alpha-default-normal.css will load for browsers matching the wide media query. The CSS within yoursubthemename-alpha-default-normal.css will not override the CSS within yoursubthemename-alpha-default.css.

To emulate this:
Place "ul.menu a {color:red}" in global.css
Place "ul.menu a {color:orange}" in yoursubthemename-alpha-default.css
Place "ul.menu a {color:yellow}" in yoursubthemename-alpha-default-normal.css

The expected result based on omega documentation is that the menu links will be yellow when viewing widescreen layout.

This however is not the case, and links will instead be orange due to the rendering order of the CSS.

A temporary fix if you'd like to design in an onion-orientated methodology would be to add the following line at the top of yoursubthemename-alpha-default-wide.css:
@import('yoursubthemename-alpha-default-normal.css')

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 7.x
Audience
Designers/themers
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here