Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
顏色屬性被用來(lái)設(shè)置文字的顏色。
顏色是通過(guò)CSS最經(jīng)常的指定:
一個(gè)網(wǎng)頁(yè)的文本顏色是指在主體內(nèi)的選擇:
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style>
body {
color: blue;
}
h1 {
color: #00ff00;
}
h2 {
color: rgb(255, 0, 0);
}
</style>
</head>
<body>
<h2>hello world</h2>
<h1>welcome to CaoZhou</h1>
</body>
</html>
注:對(duì)于W3C標(biāo)準(zhǔn)的CSS:如果你定義了顏色屬性,你還必須定義背景色屬性。
文本排列屬性是用來(lái)設(shè)置文本的水平對(duì)齊方式。
文本可居中或?qū)R到左或右,兩端對(duì)齊。
當(dāng)text-align設(shè)置為"justify",每一行被展開(kāi)為寬度相等,左,右外邊距是對(duì)齊(如雜志和報(bào)紙)。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
h1 {
text-align: center;
}
p.date {
text-align: right;
}
p.main {
text-align: justify;
}
</style>
</head>
<body>
<p class="date">2015 年 3 月 14 號(hào)</p>
<p class="main"> 從前有個(gè)書(shū)生,和未婚妻約好在某年某月某日結(jié)婚。到那一天,未婚妻卻嫁給了別人。書(shū)生受此打擊, 一病不起。 這時(shí),路過(guò)一游方僧人,從懷里摸出一面鏡子叫書(shū)生看。書(shū)生看到茫茫大海,一名遇害的女子一絲不掛地躺在海灘上。路過(guò)一人, 看一眼,搖搖頭,走了。又路過(guò)一人,將衣服脫下,給女尸蓋上,走了。再路過(guò)一人,過(guò)去,挖個(gè)坑,小心翼翼把尸體掩埋了。 僧人解釋道, 那具海灘上的女尸,就是你未婚妻的前世。你是第二個(gè)路過(guò)的人,曾給過(guò)他一件衣服。她今生和你相戀,只為還你一個(gè)情。但是她最終要報(bào)答一生一世的人,是最后那個(gè)把她掩埋的人,那人就是他現(xiàn)在的丈夫。書(shū)生大悟,病愈。
</p>
<p><b>注意:</b> 重置瀏覽器窗口大小查看 "justify" 是如何工作的。</p>
</body>
</html>
text-decoration 屬性用來(lái)設(shè)置或刪除文本的裝飾。
從設(shè)計(jì)的角度看 text-decoration屬性主要是用來(lái)刪除鏈接的下劃線(xiàn):
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.none {}
.del {
text-decoration: none;
}
</style>
</head>
<body>
<p>原來(lái)的樣子</p>
<a href="#" class="none">wwwwwwwwwwwwwwwwww</a>
<p>去掉下劃線(xiàn)</p>
<a href="#" class="del">wwwwwwwwwwwwwwwwwwwww</a>
</body>
</html>
也可以這樣裝飾文字:
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style>
h1 {
text-decoration: overline;
}
h2 {
text-decoration: line-through;
}
h3 {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
</body>
</html>
注:不建議強(qiáng)調(diào)指出不是鏈接的文本,因?yàn)檫@常常混淆用戶(hù)。
text-transform文本轉(zhuǎn)換屬性是用來(lái)指定在一個(gè)文本中的大寫(xiě)和小寫(xiě)字母。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style>
p.uppercase {
text-transform: uppercase;
}
p.lowercase {
text-transform: lowercase;
}
p.capitalize {
text-transform: capitalize;
}
</style>
</head>
<body>
<p class="uppercase">This is some text.</p>
<p class="lowercase">This is some text.</p>
<p class="capitalize">This is some text.</p>
</body>
</html>
text-indent文本縮進(jìn)屬性是用來(lái)指定文本的第一行的縮進(jìn)。
p {text-indent:50px;}
增加或減少字符之間的空間。
<style>
h1 {
letter-spacing:2px;
}
h2 {
letter-spacing:-3px;
}
</style>
指定在一個(gè)段落中行之間的空間。
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style>
p.small {
line-height: 70%;
}
p.big {
line-height: 200%;
}
</style>
</head>
<body>
<p>
This is a paragraph with a standard line-height.<br> This is a paragraph with a standard line-height.<br> The default line height in most browsers is about 110% to 120%.<br>
</p>
<p class="small">
This is a paragraph with a smaller line-height.<br> This is a paragraph with a smaller line-height.<br> This is a paragraph with a smaller line-height.<br> This is a paragraph with a smaller line-height.<br>
</p>
<p class="big">
This is a paragraph with a bigger line-height.<br> This is a paragraph with a bigger line-height.<br> This is a paragraph with a bigger line-height.<br> This is a paragraph with a bigger line-height.<br>
</p>
</body>
</html>
增加一個(gè)段落中的單詞之間的空白空間。
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style type="text/css">
p {
word-spacing: 30px;
}
</style>
</head>
<body>
<p>
This is some text. This is some text.
</p>
</body>
</html>
設(shè)置文本的垂直對(duì)齊圖像。
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style>
img{
width: 200px;
height: 100px;
}
img.top {
vertical-align: text-top;
}
img.bottom {
vertical-align: text-bottom;
}
</style>
</head>
<body>
<p>An <img src="img/logo.png" /> image with a default alignment.</p>
<p>An <img class="top" src="img/logo.png" /> image with a text-top alignment.</p>
<p>An <img class="bottom" src="img/logo.png" /> image with a text-bottom alignment.</p>
</body>
</html>
設(shè)置文本陰影。
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=640, user-scalable=no">
<title>項(xiàng)目</title>
<style>
h1{
text-shadow: 2px 2px #FF0000;
}
</style>
</head>
<body>
<h1>Text-shadow effect</h1>
</body>
</html>
本文主要介紹了CSS文本樣式實(shí)際應(yīng)用中應(yīng)該如何去操作,通過(guò)講解文本中對(duì)應(yīng)的屬性去改變文本的表現(xiàn)形式。使用豐富的效果圖的展示,能夠更直觀的看到運(yùn)行的效果,能夠更好的理解。使用Html語(yǔ)言,代碼結(jié)構(gòu)更佳的清晰,能夠幫助你更好的學(xué)習(xí)。
定義字體系列,大小,粗細(xì)和文字樣式
p {
font: font-style font-weight font-size/line-height font-family;
}
不能更換順序,必須保留font-size和font-family
定義文本外觀,如:文本顏色,對(duì)齊文本,裝飾文本,文本縮進(jìn),行間距等
tyle 屬性用于改變 HTML 元素的樣式。
<html>
<body style="background-color:PowderBlue;">
<h1>Look! Styles and colors</h1>
<p style="font-family:verdana;color:red">
This text is in Verdana and red</p>
<p style="font-family:times;color:green">
This text is in Times and green</p>
<p style="font-size:30px">This text is 30 pixels high</p>
</body>
</html>
HTML 的 style 屬性
style 屬性的作用:
提供了一種改變所有 HTML 元素的樣式的通用方法。
樣式是 HTML 4 引入的,它是一種新的首選的改變 HTML 元素樣式的方式。通過(guò) HTML 樣式,能夠通過(guò)使用 style 屬性直接將樣式添加到 HTML 元素,或者間接地在獨(dú)立的樣式表中(CSS 文件)進(jìn)行定義。
不贊成使用的標(biāo)簽和屬性
在 HTML 4 中,有若干的標(biāo)簽和屬性是被廢棄的。被廢棄(Deprecated)的意思是在未來(lái)版本的 HTML 和 XHTML 中將不支持這些標(biāo)簽和屬性。
這里傳達(dá)的信息很明確:請(qǐng)避免使用這些被廢棄的標(biāo)簽和屬性!
應(yīng)該避免使用下面這些標(biāo)簽和屬性:
HTML 樣式實(shí)例 - 背景顏色
background-color 屬性為元素定義了背景顏色:
<html> <body style="background-color:yellow"> <h2 style="background-color:red">This is a heading</h2> <p style="background-color:green">This is a paragraph.</p> </body> </html>
HTML 樣式實(shí)例 - 字體、顏色和尺寸
font-family、color 以及 font-size 屬性分別定義元素中文本的字體系列、顏色和字體尺寸:
<html> <body> <h1 style="font-family:verdana">A heading</h1> <p style="font-family:arial;color:red;font-size:20px;">A paragraph.</p> </body> </html>
HTML 樣式實(shí)例 - 文本對(duì)齊
text-align 屬性規(guī)定了元素中文本的水平對(duì)齊方式:
*請(qǐng)認(rèn)真填寫(xiě)需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。