Help:CSS


 * 1) Be familiar with hex colors before reading this.
 * 2) Many of the codes shown on this page can be used as styles.

CSS (officially known as Cascading Style Sheets) sets how a page looks. On a special sub-page on your user page, you can override the Monobook skin to create your own personal look for the wiki.

Background
CSS has three parts: A selector is the variable (officially the HTML element you're editing). A property is the attribute of the element you want to change. Each property has a value, which is what you set to change the style of the selected element.

Consider the following line: body { color: #00FF00; } The selector/element that was edited was body - all the general text on a page. The property/attribute was color - text color. The value was #00FF00 - making all text a green color.

Note the syntax for CSS. The selector is defined first, then an opening brace ({) "opens" the element for editing. Then the property appears, with a colon (:) after it, then the value (hex colors must have the # sign). Each time a value is set, a semicolon (;) is required at the end (except for the last line). Multiple lines of properties and redefined variables can occur within the curly braces ({ }), and all affect the same selected element. selector { property1: value; property2: value; property3: value; }

It is also possible to apply values to the properties of multiple selectors at once, separating them with a comma (,): selector1, selector2 { property: value; }

Example
has been kind enough to allow us to use an old version of his CSS page for an example first, using all three parts of CSS.

Let's take a look at the "body" and "a" selectors: body { font-family:Arial; font-size:10px;} a { color: #080; text-decoration: none; } a:visited { color: #050; } a:active { color: #111; }
 * 1) p-personal a.new { color: #b00; }
 * 2) p-personal a.new:visited { color:#800; }
 * 3) bodyContent a.external { color: #0a0; }
 * 4) bodyContent a.extiw:active { color: #020; }
 * The body selector covers the basic text on any page (such as what you'd see as content on a wiki page).
 * The a selector is the basic link that hasn't been clicked on recently.
 * a:active is when you are in the midst of clicking the link.
 * a:visited is the link that has been clicked recently. Often, it is simply the same color, but darker than a.
 * #p-personal a.new is the wiki-unique link-that-hasn't-been-created (red) link.
 * #p-personal a.new:visited is when you try to create a page, but don't right away, so it has a different color elsewhere until it's created, when it becomes a.
 * #bodyContent a.external is the external link.
 * #bodyContent a.extiw:active is when an external link is being clicked on.
 * Result: Normal text is changed from 12px Verdana to 10px Arial. The normal and external links are now green. When clicking on a link, the color is a dark shade of green or gray. The uncreated page links are a darker shade of red.
 * In the first example, different parts were on different lines. In fact, all of it can be on one line if you so choose. Incidentally, there is no need for a space inbetween the colon and the value as well.

Simple selectors
There are three main types of selectors: HTML elements, classes, and IDs. These are as follows:
 * Elements select plain HTML tags, such as  and  . The selector is simple the text inside the angled parentheses, such as a and img.
 * Classes are properties that almost any HTML element can be given, and define it with a given name. To select an element of a certain class, append the class name with a dot, like .classname.
 * IDs are similar to classes, but can only occur once on the page. Select them with a hash symbol (#), like #idname.

Since element selectors refer to HTML tags, they are common on all websites; classes and IDs, however, are different on every site, and those used in wikis will only work in wikis. Keep in mind that some selectors will only take certain values (experiment!). The following is a table of some important simple selectors for wiki skins:

Compound selectors
Selectors can be put together to choose, say, every link that is inside a paragraph element; this is done using spaces, so those links could be selected using p a. The second selector does not have to be directly inside the first, only somewhere within it, and it is also possible to use three selectors together, or more.

Advanced selectors
Firstly, there are pseudo-classes. These are not really there, and are "created" by the CSS. A normal element must be used for the pseudo-element to be based on, and these are separated by a colon (:). For example: a:hover {color: #aaa;} makes links grey when the cursor hovers over them. The following is a list of some useful pseudo-classes:

Next, + and > can be used to select elements more precisely. For example: ul + p {border-top: 1px solid #aaa;} puts a solid grey border at the top of every paragraph directly after an unordered list, and: ul > li {background-color: #ddf;} gives a light blue background to every list item directly inside an unordered list - as opposed to being in an element that itself is inside the    tag.

Finally, the wildcard (*) can be used to select any element. For example, p * selects every element in a paragraph.

List of properties and values
This is a list of some useful properties and some of the most important values that they take. Some values are measurements, and take units; those described here are possible options:
 * % - measured as a percentage of the container size (for width, height, padding, margin) or font size (for font-size).
 * em - measured in terms of the browser's set font size, where 1 is default and anything lower or higher varies the size proportionally. Allows the values for width, height, padding and margin to be defined relative to the font size.
 * px - measured in pixels, the smallest measurement on a display.
 * pt - only vaguely useful for fonts, where it resizes it as it would appear in a word processing program.

Some properties, such as border ones, padding and margin, take up to four values, one for each side of the element. by adding -top, -right, -left or -bottom to the property, the value for one of these can be defined. Leaving the property as it is means values are defined as follows:
 * 1 value: value is for all sides.
 * 2 values: first value is for top and bottom, second value is for right and left.
 * 3 values: first value is for top, second for right and left, third for bottom.
 * 4 values: assigned in the order top, right, bottom, left.

Some properties take a colour value. This can be either:
 * A pre-defined color name (check out this list);
 * a hex color in the form #000000 or #000, where each digit is a hexadecimal digit representing red, green or blue; or
 * rgb(red, green, blue), where red, green and blue are numbers up to 255 or 100%.

1There are properties such as border-left-width, border-bottom-style, border-right-color as well.

Putting it all together
Here's another excerpt from Wayoshi's CSS:
 * 1) content, #content table
 * 2) p-cactions ul li a { background: #fcfffc; }

.usermessage { background: #00E400; border: 1.1px dashed #060; }

no-repeat !important; }
 * 1) p-logo a { background: url(http://img.photobucket.com/albums/v506/Kimi12715/MarioWiki/Wayoshilogo3.png) 35% 50%

pre { border: 1px dashed #060; }

ul { list-style-File: url(http://img.photobucket.com/albums/v506/Kimi12715/MarioWiki/uldot.png); } h1 { font-family:Jokerman; font-size:28px;color:#117611;} h2,h3,h4,h5,h6 { color:#020; }

border: 1px dotted #272; background-color: #fdfffd; padding: 4px; } background: #fcfffc; } select { border: 1px solid #2f6f2f; } input { background-color: #fdfffd; } textarea { font-family: Boukman Old Style; font-size: 14px; } Result: Text background is a very light green. The usermessage table is redesigned to be green and have a dashed border. The logo has changed (notice after the url some specifications - these are important to have for the logo). The pre border is green. The bullet image has changed (to a green circle). The title of each page is shown in a different font and color. The rest of the headers are a dark green. The categories table has a green background, border, and some space between the text and the border. The sitenotice has the same background as the content. The select box has a green border. The input box has a light green bg. Textarea has a different font.
 * 1) catlinks {
 * 1) siteNotice {

With the above selectors, properties, and values above, you should be able to stylize your wiki to your needs very well.

Creating your Monobook.css
You have your own skin page at User:Username/monobook.css</tt>, with stress on the lower case m. When editing it, you should see some new text: Tip: Use the 'Show preview' button to test your new CSS/JS before saving. Whatever is entered into here is put into a style sheet (inbetween and tags). So, it is only necessary to put the list of selectors you want to change, with their properties and values, no "header" or "footer". If you want to add comments (text that the CSS won't read), put it inbetween /*</tt> and */</tt>. While you can preview the new CSS, some changes (like to the categories table) require you to save it first.

To see the changes after saving, hard refresh (press the F5 key, sometimes Ctrl + F5). Congratulations, you now have your own unique skin.