帮助:HTML

本页使用了标题或全文手工转换
维基百科,自由的百科全书

要使用HTML代码,无需额外处理,直接输入HTML标记即可。


例子

span

<span>是通用内联文字容器,目前可以默认使用。span可以使用id、class、style来定义样式:

<span style="color:red">style</span>
<span id="randomfooid">id</span>
<span class="importantmessage">class</span>

生成:

style id class

短语元素

span元素是用来对行内元素进行分组,以便通过样式对它们进行格式化。它本身没有任何意思。而短语元素是专门为有特殊意义的文字内容而设。

各短语元素的定义
<em> 呈现为强调后的文本。
<strong> 定义重要的文本。
<dfn> 定义一个定义项目。
<code> 定义电脑代码文本。
<samp> 定义样本文本。
<kbd> 定义键盘文本。它表示文本是从键盘上键入的,常用在电脑相关文档或手册中。
<var> 定义变量。您可以将此标签与<pre><code> 标签配合使用。
<cite> 定义引用。可使用该标签对参考文献的引用进行定义,比如书籍或杂志的标题。

短语元素同样可以用class、id、style来定义样式。 例如:

<em>Default </em>
<em style="color:red;font-style:normal">CSS style</em>

生成

Default CSS style

这不仅仅吸引用户的注意力,还可以提醒使用非可视化浏览器或有视力障碍的用户。

font

注意,此元素不推荐使用,而以<span>替代。

对于一些属性,比如颜色、字体、大小,只能这么用:

<font size="200%">大</font>
<font color="red" face="標楷體">紅</font>字和
<font color="#0000ff" face="Comic Sans MS">Blue</font> text。

生成

字和 Blue text

div

<div>元素定义HTML文档中的分隔(division)或部分(section)。 <div>元素常用于组合块级元素,以便通过样式表来对这些元素进行格式化。 例如让多组文字以红色显示,可以这么运用:

 <div style="color:red">
  <p>This is a sentence.<em> This is an emphasized text.</em></p>
  <p>This is a paragraph.</p>
 </div>

生成

This is a sentence. This is an emphasized text.

This is a paragraph.

过时的HTML

新一代HTML的设计是尽量仅包含结构和内容,样式的显示就交由CSS负责。所以,有些HTML元素和属性已经过时,甚至新版HTML不再支持。尽管这些过时的HTML元素和属性在流行的浏览器仍然有效,但鼓励编辑者使用新规格的HTML来编写页面。如果要定义文字的样式,可以用style属性来加入CSS。

过时的HTML元素 替代的HTML元素 意思
<font></font>
<span><span>
定义文字效果。亦可使用{{font}}{{color}}等模板。
<s></s>
<del></del>
<span style="text-decoration: line-through; "></span>
添加删除线。
<center></center>
<div style="text-align: center; "></div>
<div style="width: auto; margin-left: auto; margin-right: auto; "></div>
置中文字,也可以使用模板{{Center}}
<big></big>
<span style="font-size: large; "></span>
或使用{{big}}等模板
放大文字。
<small></small>
<span style="font-size: small; "></span>
或使用{{small}}{{smaller}}等模板
缩小文字。注意:如果此标签是用来表示注释等内容的,则不是过时的。
<strong></strong>
<b></b>
<span style="font-weight: bold; "></span>
加粗文本。如果加粗文本是为了强调内容,则不是过时的。
<u></u>
<span style="text-decoration: underline; "></span>
添加下划线,但是非超链接文字不应添加。


过时的HTML属性 替代的CSS属性
face="字体" font-family: 字体;
color="颜色" color: 颜色;
bgcolor="颜色" background-color: 颜色;
size="大小" font-size: 大小;
align="水平位置" text-align: 水平位置;

接下来从Sanitizer.php摘录的原始码附加的说明了什么属性是可用的。

 /* private */ 
 function removeHTMLtags( $text )
 {
  wfProfileIn( "OutputPage::removeHTMLtags" );
  $htmlpairs = array( # Tags that must be closed
   "b", "i", "u", "font", "big", "small", "sub", "sup", "h1",
   "h2", "h3", "h4", "h5", "h6", "cite", "code", "em", "s",
   "strike", "strong", "tt", "var", "div", "center",
   "blockquote", "ol", "ul", "dl", "table", "caption", "pre",
   "ruby", "rt" , "rb" , "rp"
  );
  $htmlsingle = array(
   "br", "p", "hr", "li", "dt", "dd"
  );
  $htmlnest = array( # Tags that can be nested--??
   "table", "tr", "td", "th", "div", "blockquote", "ol", "ul",
   "dl", "font", "big", "small", "sub", "sup"
  );
  $tabletags = array( # Can only appear inside table
   "td", "th", "tr"
  );

  $htmlsingle = array_merge( $tabletags, $htmlsingle );
  $htmlelements = array_merge( $htmlsingle, $htmlpairs );

  $htmlattrs = array( # Allowed attributes--no scripting, etc.
   "title", "align", "lang", "dir", "width", "height",
   "bgcolor", "clear", /* BR */ "noshade", /* HR */
   "cite", /* BLOCKQUOTE, Q */ "size", "face", "color",
   /* FONT */ "type", "start", "value", "compact",
   /* For various lists, mostly deprecated but safe */
   "summary", "width", "border", "frame", "rules",
   "cellspacing", "cellpadding", "valign", "char",
   "charoff", "colgroup", "col", "span", "abbr", "axis",
   "headers", "scope", "rowspan", "colspan", /* Tables */
   "id", "class", "name", "style" /* For CSS */
  );

比如元素<a>在维基代码中被禁止使用,因此

<a href="https://meta.wikimedia.org/wiki/Main_Page">Main Page</a>

生成

<a href="https://meta.wikimedia.org/wiki/Main_Page">Main Page</a>

是文字而不是链接。

解析器扩展标签

MediaWiki软件加入了一批与HTML标签类似的解析器扩展标签,其中解析器标签(Parser tag)由MediaWiki定义,而扩展标签由扩展程序提供。Special:版本资讯列有所有标签。欲知扩展标签用法,可在Special:版本资讯搜索对应的扩展程序,或者点击下面的链接。

解析器标签(Parser tag)

<gallery>, <nowiki>, <pre>

扩展标签:

<categorytree>, <charinsert>, <hiero>,<imagemap>,<inputbox>, <math>, <poem>, <ref>, <references>,<syntaxhighlight> (也可写作<source>), <timeline>

外部链接