Design Your Own CSS Theme

Posted by michal-frackowiak on 19 Aug 2006 11:29, last edited by PeterMortensen on 30 Aug 2015 16:30

Tags: color colour css customize layout themes

rating: +33+x

This document is a work-in-progress. Please contribute if you wish!

This is a how-to that describes a way to create your own appearance for your site.

Introduction

A theme is a structured template, written in a markup language called Cascading Style Sheets (CSS), that controls the appearance and graphical layout of a page. The theme defines the font to be used, its size, the location of text, colors, and background images. However, themes are independent from the actual informational content of the page, so they make it possible to change the visual presentation without having to re-enter the actual text or other data.

Wikidot.com already offers a several basic CSS themes to choose from. But it is certainly never a bad idea to create your very own look for your site. The whole trick is to write new CSS code that is placed upon the existing themes so you do not have to write everything from scratch. E.g. to just change most of the colors you need to produce as much as 20 lines of code. And this HOWTO will tell you how.

There are collections of user-created CSS-themes on open wikis:

Before you start your own theme you should have a look about possible and existing layouts!

Basics

When creating a new theme you will have to extend already existing themes. Custom themes are created per site and are available only within a given site.

To create new themes you will certainly need some CSS and design skills. You can learn a lot at sites like the following:

W3Schools - CSS
tutorial and reference documents.
Web 2.0 Design Guide - Why it works
"It seems that perfection is reached not when there is nothing left to add, but when there is nothing left to take away." - Antoine de Saint-Exupéry
Zen Garden - The Beauty of CSS Design
A demonstration of what can be accomplished visually through CSS-based design.
css/edge
A rejection of what's practical in favor of what's possible. complexspiral example
ColorBlender
makes it very quick and easy to create a color scheme for e.g. a website.

Step-by-Step Guide

Step 1: Manage the Site's Appearance

Go to the Site Manager (by default available at the page admin:manage). There should be a link on the side bar of your pages.

Click on Appearance » Custom Theme.

Of course you will need an administrator role within the Site.

Step 2: Create a Custom Theme

If you already have some custom themes defined you should see them listed. In order to create a new one:

  • Click create a new theme
  • Choose a name for the theme
  • Choose a theme you want to extend…

You can basically extend any theme available. However if you want to start from a plain look as much as possible than you should choose Base theme. Every theme on Wikidot.com extends the Base theme. This theme contains basic layout for pages, dialogs, forum, etc. We will come back to it later.

But if you just want to change e.g. colors in an already available theme, then choose this theme (e.g. change colors in the Cappuccino theme).

At the moment suppose you want to extend the Base theme.

Choose an editing method

The box with the title 'CSS code' shows the CSS in your custom theme. It begins blank (it doesn't display the CSS from the theme you are extending, only the additional CSS you build on top of this. The additional code will appear after the end of the original theme and override existing definitions).

There are two ways to manage your CSS code: put it directly into the box or (which we recommend) keep all the CSS code in a separate special page on your wiki, and use the 'import' button to import it to the box. This way you can easily keep revisions of your theme as you do with wiki pages. The CSS is extracted from the first [[code]] … [[/code]] block in the specified page. The process of taking code from the 'sync' page isn't an automatic one - so each time you change it you have to use the custom theme administration controls and click "import" and "save theme".

So we recommend here to open a new window in your browser and create a (empty) page called css:mytheme (or any other that suits you). Put this name in the theme form.

The “save theme” function will not export the code back in your CSS wiki-page but record the content of the box as a custom theme. If you use this method you must:

  1. Edit and save your custom CSS code in your css:mytheme wiki page ( this is not an active CSS but just text data)
  2. Create or select your custom theme from manage site / Appearance / custom themes
  3. "import" the CSS data from css:mytheme wiki page
  4. "Save theme" in order to save CSS data in the real custom theme.

Select navigation elements

Decide if you want to use side/top navigation (menu) elements. Select whether your theme will use it or not?

Save the theme

Even if you do not have CSS ready yet - you will write it later.

Step 3: Write CSS for the Theme

This is the most important step. To do this properly you will have to learn first how the theme you are about to extend is implemented.

For the Base theme look at the CSS file: http://www.wikidot.com/common--theme/base/css/style.css

This base CSS includes styles for dialogs (window pop-ups), forums, the wikidot editor, autocomplete and code highlighting near the bottom of the file, all of which you can style in your custom theme.

If you aren't sure of the address of the CSS for the theme you are already using just check the source code on one or your pages (look for 'style type="text/css" id="internal-style")'.

Structure of the page

Most likely you will need to know the DOM structure of the page i.e. what elements are there, what classes and ids, etc. Each of the pages has more or less the same layout. You can learn this by:

  • Looking at the HTML source code (in your browser) for a page
  • Reading the Layout Reference document
  • Using the Web Developer extension for Firefox and clicking Outline » Outline current element
  • Exploring the DOM structure by using the DOM Inspector (Firefox has it) or equivalent tools

Learn by example

Let us see how the Flannel Ocean theme is defined - it directly extends the Base theme. The CSS is located here.

What the style actually does:

  • Defines layout for header, footer, side bar and page content
  • Defines font sizes and colors for elements such as headings, anchor links, etc.
  • Changes colors for the dialog windows
  • Changes some colors for the forum

If you like the Flannel theme but you just want to change the colors you can simply extend this theme and redefine only the colors! The same for other themes of course. The easiest way in each case is just to copy&paste blocks of code from existing themes to your own theme.

Below is a list of selected themes and their styles

Flannel http://www.wikidot.com/common--theme/flannel/css/style.css
Flannel (no side bar) http://www.wikidot.com/common--theme/flannel-no-side-bar/css/style.css
Flannel Ocean http://www.wikidot.com/common--theme/flannel-ocean/css/style.css
Flannel Ocean (no side bar) http://www.wikidot.com/common--theme/flannel-ocean-no-side-bar/css/style.css
Flannel Nature http://www.wikidot.com/common--theme/flannel-nature/css/style.css
Flannel Nature (no side bar) http://www.wikidot.com/common--theme/flannel-nature-no-side-bar/css/style.css
Cappuccino http://www.wikidot.com/common--theme/cappuccino/css/style.css
Cappucino (side bar on right ) http://www.wikidot.com/common--theme/cappucino-right/css/style.css

Update theme

So let us assume you have embedded the CSS code within the page css:mytheme. Go to Site Manager » Appearance » Custom themes and open your new theme for editing. If you have the source page configured, just click import and see what happens.

Save theme of course.

Preview theme

To begin with a custom theme won't be assigned to any pages, so you won't immediately see the results of your work. You can preview the theme in two ways:

  • you can assign the theme to a particular page category by going to Site Manager » Appearance » Themes (as you would do for any other theme)
  • you can use ThemePreviewer module - just put it on your pages somewhere and it will allow you to preview available themes on your page.

Step 4: Test your Theme!

There are many browser quirks. What some browsers render properly others can not understand at all. Please test your theme with at least major browsers (Firefox, Internet Explorer, and Opera).

CSS Validator
Copy and paste your code into the Validator to check for errors.

Step 5: Assign Themes to Categories

When your theme is ready - go to Site Manager » Appearance » Themes and set the new theme for the page categories you want. And… that should be all!

General tips

  • Do not use pixel units (px) for font size; wherever possible (font size, layout) use font-based units (em) or percentage (%)
  • Keep your design clean and readable
  • Test CSS with different browsers

Authors

michal-frackowiakmichal-frackowiak. Please visit his/her userPage.

Add a New Comment

Related articles

Comments

Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.