Wikipedia:WikiProject Usability/HTML: Difference between revisions
Content deleted Content added
nav menu |
|||
(30 intermediate revisions by 17 users not shown) | |||
Line 1:
{{cleanup|date=November 2010}}
Wikipedia allows the use of [[HTML]], and through the style="" and class="" elements, the use of [[CSS]]. The use of HTML instead of [[Wiki markup]] is strongly discouraged, because it makes the edit pages hard to read, and on a wiki the readability of the edit page is almost as important as the readability of the page itself, because nobody wants to edit something that they don't understand. ▼
{{Wikipedia:WikiProject Usability/Navigation menu | Miscellaneous}}
Wiki supports a subset of [[XHTML]], e.g. '''<br />''' instead of '''<br>'''.
Wikipedia allows the use of [[HTML]] directly, and the use of [[Cascading Style Sheets|CSS]] through the <code>style="<var>[…]</var>"</code> and <code>class="<var>[…]</var>"</code> attributes.
However, occasionally, such as when you are creating tables, notices, and so on, for which there is no markup defined, it must be used.▼
We believe that:
* The use of HTML instead of [[Wiki markup]] is discouraged
* If HTML and CSS ''must'' be used, editors should know how to use them properly, with regard to:
** [[W3C]] standards
** Cross-browser compatibility
== Why HTML should be used conservatively ==
HTML is simple to use - just put a pair of tags around a word, <nowiki><i>italics</i></nowiki>, and it will show up <i>as the tags defined it</i>. Most HTML elements, like bold (strong, b), italic (em, i), list (li), heading (h1, h2...) and even table (table) have their equivelant in the markup, so should be avoided. The CSS, which you can think of as the "display attributes" may be added to the markup itself - this is covered later.▼
▲
▲
== HTML and CSS primer ==
▲HTML is simple to use - just put a pair of tags around
:<nowiki><span class="noprint" style="color:red">red text that does not show up when printed</span></nowiki> ▼
produces ▼
:<span class="noprint" style="color:red">red text that does not show up when printed</span>. ▼
Sometimes, however, there isn't any appropriate wikicode for what you want to mark up. In this situation, there are two possible contexts, block and inline. Paragraphs, headings, lists and tables are block elements (they start on a new line), <code><nowiki><b></nowiki></code> & <code><nowiki><i></nowiki></code> are inline elements. In each context, there is a generic HTML element available:
*<code><nowiki><span></nowiki></code>: inline
*<code><nowiki><div></nowiki></code>: block
These span and div tags need <code>class</code> or <code>style</code> attributes to change the appearance of the page.
=== List of style attributes ===▼
▲:<code><nowiki><span class="noprint" style="color:red;"></nowiki>red text that does not show up when printed<nowiki></span>
▲:
Where possible, an appropriate class should be used instead of inline styles, to avoid clutter in the edit window and to be able to change the appearance of, for example, all [[Wikipedia:article message boxes|article message boxes]] at once.
However, when you ''must'' use inline styles, you can do this. They take the following form: <code>style="<var>p</var>: <var>v</var>; <var>p</var>: <var>v</var>; <var>…</var>"</code>, where <var>p</var> is a property and <var>v</var> the value you want to assign to that property.
Before listing attributes, you should get to know how to represent certain values:▼
*Color may be represented using hex form (#000000 being black, #ff0000 being red, for example), or using names (red, green...)▼
<!-- you'll note how messy this section looks in the editor, due to all the code -->▼
▲*Color
* '''"color: [color];"''' - the foreground color. ▼
*Size can be represented using [[em (typography)|em]], [[percent|%]] and [[pixel|px]], among others.
** <tt><nowiki><span style="color:red;">test</span></nowiki></tt> --> <span style="color:red;">test</span>▼
==== Basic properties ====
* '''"background: [color];"''' - 'shorthand' for several background properties, including image. Used for background color▼
''Please note: this page does not want to encourage the use of bright, or non-standard colors. They are used for clearer examples. Please see [[Wikipedia:WikiProject Usability/Color]]''
** <tt><nowiki><span style="background:black; color:#ff0000;">test</span></nowiki></tt> --> <span style="background:black; color:#ff0000;">test</span>▼
▲<!-- you'll note how messy this section looks in the editor, due to all the code -->
* '''"border:''' [thickness] [type] [color];" - the border: color, thickness, type. Type may be solid, outset, dashed, and others▼
** <tt><nowiki><span style="border: 1px outset blue; background:yellow;">test</span></nowiki></tt> --> <span style="border: 1px outset blue; background:yellow;">test</span>▼
** <
▲* <code>'''
** <tt><nowiki>foo<span style="border: 1px solid red; background:transparent;">test</span>bar</nowiki></tt> --> foo<span style="border: 1px solid red; background:transparent;">test</span>bar▼
▲** <
*** You'll note that "transparent" is used for the background here. The standard background of wikipedia is #f8fcff, so if you put "white" and neglect the border, you <span style="background:white;">may notice a very slight (but innapropriate) difference in color.</span> Transparent should usually be used.▼
▲* <code>'''
▲** <
* '''"padding: [size];"''' - usually, the "spacing" on the ''inside'' of the border. 1, 2, or 4 sizes may be specified. ▼
** <
** <
▲*** You'll note that "transparent" is used for the background here. The standard background
*** Two values: [top/bottom] [right/left].▼
▲* <code>'''
** <tt><nowiki>foo<span style="border: 1px solid red; padding: .1em .5em 1em 2em;">test</span>bar</nowiki></tt> --> foo<span style="border: 1px solid red; padding: .1em .5em 1em 2em;">test</span>bar▼
▲** <
▲** <
** <code><nowiki>foo<span style="border: 1px solid red; padding: .1em .5em 1em;">test</span>bar</nowiki></code> → foo<span style="border: 1px solid red; padding: .1em .5em 1em;">test</span>bar
*** Three values: [top] [right & left] [bottom].
▲** <
***Four values: [top] [right] [bottom] [left] (clockwise).
* <code>'''
** <
** <
** <
** <code><nowiki>foo<span style="border: 1px solid red; margin: 0em 1em 2em 3;">test</span>bar</nowiki></code> → foo<span style="border: 1px solid red; margin: 0em 1em 2em 3em;">test</span>bar
** <code><nowiki>foo<span style="border: 1px solid red; margin: 0em -.3em;">test</span>bar</nowiki></code> → foo<span style="border: 1px solid red; margin: 0em -.3em;">test</span>bar
▲* '''"margin: [size];"''' - usually, the "spacing" on the ''outside'' of the border. It's also the distance at which other elements should be "kept away" at. 1, 2, or 4 sizes may be specified, exactly as in "padding". Many browsers will ignore "top/bottom" for margins on ''inline'' elements.
{{Main|Wikipedia:Catalogue of CSS classes}}
▲** <tt><nowiki>foo<span style="border: 1px solid red; margin: 1em;">test</span>bar</nowiki></tt> --> foo<span style="border: 1px solid red; margin: 1em;">test</span>bar
* syntax: <code>class="<var>class<sub>1</sub></var> <var>class<sub>2</sub></var> …"</code>
▲** <tt><nowiki>foo<span style="border: 1px solid red; margin: 3em 1em;">test</span>bar</nowiki></tt> --> foo<span style="border: 1px solid red; margin: 3em 1em;">test</span>bar
* <code>noprint</code> and <code>metadata</code> – will not get printed onto paper. <code>metadata</code> is more descriptive for actual metadata, like notices, but the intent of noprint is much clearer.
▲** <tt><nowiki>foo<span style="border: 1px solid red; margin: 0em 1em 0em 2em;">test</span>bar</nowiki></tt> --> foo<span style="border: 1px solid red; margin: 0em 1em 0em 2em;">test</span>bar
** <code><nowiki><span class="noprint">This will not show up when printed</span></nowiki></code>
* [[meta:Help:HTML in wikitext]]
[[Category:WikiProject Usability|HTML]]
▲** <nowiki><span class="noprint">will not show up when printed</span></nowiki> - <span class="noprint">will not show up when printed</span>
|