HTML Center 元素 ( <center>) 是個(gè) 塊級元素,可以包含段落,以及其它塊級和內(nèi)聯(lián)元素。這個(gè)元素的整個(gè)內(nèi)容在它的上級元素中水平居中(通常是 <body>)。
將 HTML 網(wǎng)頁中的文本進(jìn)行水平居中處理:
<!doctype html> <html> <head> <meta charset="UTF-8"> <title>菜鳥教程(cainiaoplus.com)</title> </head> <body> <center>This text will be centered. <p>So will this paragraph.</p></center> <div style="text-align:center">This text will be centered. <p>So will this paragraph.</p></div> 注意:向 div 或者 p 元素應(yīng)用 text-align:center 會(huì)使這些元素的內(nèi)容居中,同時(shí)保留其整體大小不變。 </body> </html>測試看看 ?/?
IEFirefoxOperaChromeSafari
所有主流瀏覽器都支持 <center> 標(biāo)簽。
HTML5 不支持 <center> 標(biāo)簽。請用 CSS 代替。
在 HTML 4.01 中,<center> 元素 已廢棄。
<center> 對其所包括的文本進(jìn)行水平居中。
提示:請使用 CSS 樣式來居中文本!在 CSS 教程中您能了解到更多關(guān)于居中文本的細(xì)節(jié)。
HTML5 不支持 <center> 標(biāo)簽,HTML 4.01 已廢棄 <center> 標(biāo)簽。
在 HTML 4.01 中,<center> 標(biāo)簽支持如下標(biāo)準(zhǔn)屬性:
屬性 | 值 | 描述 |
---|---|---|
class | classname | 指定元素的類名 |
dir | rtl ltr | 指定元素中內(nèi)容的文本方向 |
id | id | 指定元素的唯一 id |
lang | language_code | 指定元素中內(nèi)容的語言代碼 |
style | style_definition | 指定元素的行內(nèi)樣式 |
title | text | 指定元素的額外信息 |
如需完整的描述,請?jiān)L問標(biāo)準(zhǔn)屬性。
在 HTML 4.01 中,<center> 標(biāo)簽支持如下事件屬性:
屬性 | 值 | 描述 |
---|---|---|
onclick | script | 當(dāng)鼠標(biāo)被單擊時(shí)執(zhí)行腳本 |
ondblclick | script | 當(dāng)鼠標(biāo)被雙擊時(shí)執(zhí)行腳本 |
onmousedown | script | 當(dāng)鼠標(biāo)按鈕被按下時(shí)執(zhí)行腳本 |
onmousemove | script | 當(dāng)鼠標(biāo)指針移動(dòng)時(shí)執(zhí)行腳本 |
onmouseout | script | 當(dāng)鼠標(biāo)指針移出某元素時(shí)執(zhí)行腳本 |
onmouseover | script | 當(dāng)鼠標(biāo)指針懸停于某元素之上時(shí)執(zhí)行腳本 |
onmouseup | script | 當(dāng)鼠標(biāo)按鈕被松開時(shí)執(zhí)行腳本 |
onkeydown | script | 當(dāng)鍵盤被按下時(shí)執(zhí)行腳本 |
onkeypress | script | 當(dāng)鍵盤被按下后又松開時(shí)執(zhí)行腳本 |
onkeyup | script | 當(dāng)鍵盤被松開時(shí)執(zhí)行腳本 |
如需完整的描述,請?jiān)L問事件屬性。