自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

一篇文章帶你了解 CSS 文本樣式

開發(fā) 前端
本文主要介紹了CSS文本樣式實(shí)際應(yīng)用中應(yīng)該如何去操作,通過講解文本中對(duì)應(yīng)的屬性去改變文本的表現(xiàn)形式。使用豐富的效果圖的展示,能夠更直觀的看到運(yùn)行的效果,能夠更好的理解。使用Html語(yǔ)言,代碼結(jié)構(gòu)更佳的清晰,能夠幫助你更好的學(xué)習(xí)。

[[402556]]

大家好,我是IT共享者,人稱皮皮。這篇文章我們來講講CSS的文本樣式。

一、文本顏色Color

顏色屬性被用來設(shè)置文字的顏色。

顏色是通過CSS最經(jīng)常的指定:

  • 十六進(jìn)制值 - 如"#FF0000"。
  • 一個(gè)RGB值 - "RGB(255,0,0)"。
  • 顏色的名稱 - 如"紅"。

一個(gè)網(wǎng)頁(yè)的文本顏色是指在主體內(nèi)的選擇:

  1. <html> 
  2.     <head> 
  3.         <meta charset="utf-8"
  4.         <meta name="viewport" content="width=640, user-scalable=no"
  5.         <title>項(xiàng)目</title> 
  6.         <style> 
  7.             body { 
  8.                 color: blue; 
  9.             } 
  10.  
  11.             h1 { 
  12.                 color: #00ff00; 
  13.             } 
  14.  
  15.             h2 { 
  16.                 color: rgb(255, 0, 0); 
  17.             } 
  18. </style> 
  19.     </head> 
  20.  
  21.     <body> 
  22.         <h2>hello world</h2> 
  23.         <h1>welcome to CaoZhou</h1> 
  24.     </body> 
  25.  
  26. </html> 

注:對(duì)于W3C標(biāo)準(zhǔn)的CSS:如果你定義了顏色屬性,你還必須定義背景色屬性。

二、屬性

1. text-align 文本的對(duì)齊方式

文本排列屬性是用來設(shè)置文本的水平對(duì)齊方式。

文本可居中或?qū)R到左或右,兩端對(duì)齊。

當(dāng)text-align設(shè)置為"justify",每一行被展開為寬度相等,左,右外邊距是對(duì)齊(如雜志和報(bào)紙)。

  1. <!doctype html> 
  2. <html lang="en"
  3.  
  4.     <head> 
  5.         <meta charset="UTF-8"
  6.         <title>Document</title> 
  7.         <style> 
  8.             h1 { 
  9.                 text-align: center; 
  10.             } 
  11.  
  12.             p.date { 
  13.                 text-align: right
  14.             } 
  15.  
  16.             p.main { 
  17.                 text-align: justify; 
  18.             } 
  19. </style> 
  20.     </head> 
  21.  
  22.     <body> 
  23.  
  24.         <p class="date">2015 年 3 月 14 號(hào)</p> 
  25.         <p class="main"> 從前有個(gè)書生,和未婚妻約好在某年某月某日結(jié)婚。到那一天,未婚妻卻嫁給了別人。書生受此打擊, 一病不起。  這時(shí),路過一游方僧人,從懷里摸出一面鏡子叫書生看。書生看到茫茫大海,一名遇害的女子一絲不掛地躺在海灘上。路過一人, 看一眼,搖搖頭,走了。又路過一人,將衣服脫下,給女尸蓋上,走了。再路過一人,過去,挖個(gè)坑,小心翼翼把尸體掩埋了?! ∩私忉尩?, 那具海灘上的女尸,就是你未婚妻的前世。你是第二個(gè)路過的人,曾給過他一件衣服。她今生和你相戀,只為還你一個(gè)情。但是她最終要報(bào)答一生一世的人,是最后那個(gè)把她掩埋的人,那人就是他現(xiàn)在的丈夫。書生大悟,病愈。 
  26.  
  27.         </p> 
  28.         <p><b>注意:</b> 重置瀏覽器窗口大小查看 "justify" 是如何工作的。</p> 
  29.     </body> 
  30.  
  31. </html> 

2. text-decoration文本修飾

text-decoration 屬性用來設(shè)置或刪除文本的裝飾。

從設(shè)計(jì)的角度看 text-decoration屬性主要是用來刪除鏈接的下劃線:

  1. <!doctype html> 
  2. <html lang="en"
  3.  
  4.     <head> 
  5.         <meta charset="UTF-8"
  6.         <title>Document</title> 
  7.         <style> 
  8.             .none {} 
  9.  
  10.             .del { 
  11.                 text-decoration: none; 
  12.             } 
  13. </style> 
  14.     </head> 
  15.  
  16.     <body> 
  17.         <p>原來的樣子</p> 
  18.         <a href="#" class="none">wwwwwwwwwwwwwwwwww</a> 
  19.         <p>去掉下劃線</p> 
  20.         <a href="#" class="del">wwwwwwwwwwwwwwwwwwwww</a> 
  21.     </body> 
  22.  
  23. </html> 

也可以這樣裝飾文字:

  1. <html> 
  2.     <head> 
  3.         <meta charset="utf-8"
  4.         <meta name="viewport" content="width=640, user-scalable=no"
  5.         <title>項(xiàng)目</title> 
  6.         <style> 
  7.             h1 { 
  8.                 text-decoration: overline; 
  9.             } 
  10.  
  11.             h2 { 
  12.                 text-decoration: line-through; 
  13.             } 
  14.  
  15.             h3 { 
  16.                 text-decoration: underline; 
  17.             } 
  18. </style> 
  19.     </head> 
  20.  
  21.     <body> 
  22.         <h1>This is heading 1</h1> 
  23.         <h2>This is heading 2</h2> 
  24.         <h3>This is heading 3</h3> 
  25.     </body> 
  26.  
  27. </html> 

注:不建議強(qiáng)調(diào)指出不是鏈接的文本,因?yàn)檫@常?;煜脩?。

3. text-transform文本轉(zhuǎn)換

text-transform文本轉(zhuǎn)換屬性是用來指定在一個(gè)文本中的大寫和小寫字母。

  • uppercase:轉(zhuǎn)換為全部大寫。
  • lowercase:轉(zhuǎn)換為全部小寫。
  • capitalize :每個(gè)單詞的首字母大寫。
  1. <!DOCTYPE html> 
  2. <html> 
  3.  
  4.     <head> 
  5.         <meta charset="utf-8"
  6.         <meta name="viewport" content="width=640, user-scalable=no"
  7.         <title>項(xiàng)目</title> 
  8.         <style> 
  9.             p.uppercase { 
  10.                 text-transform: uppercase; 
  11.             } 
  12.  
  13.             p.lowercase { 
  14.                 text-transform: lowercase; 
  15.             } 
  16.  
  17.             p.capitalize { 
  18.                 text-transform: capitalize; 
  19.             } 
  20. </style> 
  21.     </head> 
  22.  
  23.     <body> 
  24.         <p class="uppercase">This is some text.</p> 
  25.         <p class="lowercase">This is some text.</p> 
  26.         <p class="capitalize">This is some text.</p> 
  27.     </body> 
  28.  
  29. </html> 

4. text-indent文本縮進(jìn)

text-indent文本縮進(jìn)屬性是用來指定文本的第一行的縮進(jìn)。

  1. p {text-indent:50px;} 

5. letter-spacing 設(shè)置字符間距

增加或減少字符之間的空間。

  1. <style> 
  2.      h1 { 
  3.        letter-spacing:2px; 
  4.       h2 { 
  5.         letter-spacing:-3px; 
  6. </style> 

6. line-height設(shè)置行高

指定在一個(gè)段落中行之間的空間。

  1. <html> 
  2.     <head> 
  3.         <meta charset="utf-8"
  4.         <meta name="viewport" content="width=640, user-scalable=no"
  5.         <title>項(xiàng)目</title> 
  6.         <style> 
  7.             p.small { 
  8.                 line-height: 70%; 
  9.             } 
  10.  
  11.             p.big { 
  12.                 line-height: 200%; 
  13.             } 
  14. </style> 
  15.     </head> 
  16.  
  17.     <body> 
  18.         <p> 
  19.             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> 
  20.         </p> 
  21.  
  22.         <p class="small"
  23.             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> 
  24.         </p> 
  25.  
  26.         <p class="big"
  27.             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> 
  28.         </p> 
  29.  
  30.     </body> 
  31.  
  32. </html> 

7. word-spacing 設(shè)置字間距

增加一個(gè)段落中的單詞之間的空白空間。

  1. <html> 
  2.     <head> 
  3.         <meta charset="utf-8"
  4.         <meta name="viewport" content="width=640, user-scalable=no"
  5.         <title>項(xiàng)目</title> 
  6.         <style type="text/css"
  7.             p { 
  8.                 word-spacing: 30px; 
  9.             } 
  10. </style> 
  11.     </head> 
  12.  
  13.     <body> 
  14.  
  15.         <p> 
  16.             This is some text. This is some text. 
  17.         </p> 
  18.  
  19.     </body> 
  20.  
  21. </html> 

8. vertical-align 設(shè)置元垂直居中

設(shè)置文本的垂直對(duì)齊圖像。

  1. <html> 
  2.     <head> 
  3.         <meta charset="utf-8"
  4.         <meta name="viewport" content="width=640, user-scalable=no"
  5.         <title>項(xiàng)目</title> 
  6.         <style> 
  7.             img{ 
  8.                 width: 200px; 
  9.                 height: 100px; 
  10.             } 
  11.             img.top { 
  12.                 vertical-align: text-top
  13.  
  14.             } 
  15.  
  16.             img.bottom { 
  17.                 vertical-align: text-bottom; 
  18.  
  19.             } 
  20. </style> 
  21.     </head> 
  22.  
  23.     <body> 
  24.         <p>An <img src="img/logo.png"  /> image with a default alignment.</p> 
  25.         <p>An <img class="top" src="img/logo.png" /> image with a text-top alignment.</p> 
  26.         <p>An <img class="bottom" src="img/logo.png" /> image with a text-bottom alignment.</p> 
  27.     </body> 
  28.  
  29. </html> 

9. text-shadow 設(shè)置文本陰影

設(shè)置文本陰影。

  1. <html> 
  2.     <head> 
  3.         <meta charset="utf-8"
  4.         <meta name="viewport" content="width=640, user-scalable=no"
  5.         <title>項(xiàng)目</title> 
  6.         <style> 
  7.          h1{ 
  8.             text-shadow: 2px 2px #FF0000; 
  9.      } 
  10. </style> 
  11.     </head> 
  12.  
  13.     <body> 
  14.     <h1>Text-shadow effect</h1> 
  15.     </body> 
  16.  
  17. </html> 

三、總結(jié)

本文主要介紹了CSS文本樣式實(shí)際應(yīng)用中應(yīng)該如何去操作,通過講解文本中對(duì)應(yīng)的屬性去改變文本的表現(xiàn)形式。使用豐富的效果圖的展示,能夠更直觀的看到運(yùn)行的效果,能夠更好的理解。使用Html語(yǔ)言,代碼結(jié)構(gòu)更佳的清晰,能夠幫助你更好的學(xué)習(xí)。

責(zé)任編輯:姜華 來源: IT共享之家
相關(guān)推薦

2020-11-03 19:18:28

CSS對(duì)齊文本

2021-03-26 09:57:51

SVGHtml基礎(chǔ)SVG圖像

2021-04-07 06:11:37

Css前端CSS定位知識(shí)

2021-01-25 05:39:54

Css前端Border

2023-05-12 08:19:12

Netty程序框架

2021-06-30 00:20:12

Hangfire.NET平臺(tái)

2020-11-17 11:10:21

CSS選擇器HTML

2020-12-18 05:40:37

CSS clearHtml

2020-11-27 08:51:29

CSSOpacity透明度

2023-07-30 15:18:54

JavaScript屬性

2023-05-08 08:21:15

JavaNIO編程

2021-01-26 23:46:32

JavaScript數(shù)據(jù)結(jié)構(gòu)前端

2021-03-09 14:04:01

JavaScriptCookie數(shù)據(jù)

2021-06-24 09:05:08

JavaScript日期前端

2021-09-27 09:18:30

ListIterato接口方法

2023-09-06 14:57:46

JavaScript編程語(yǔ)言

2024-01-30 13:47:45

2024-04-19 14:23:52

SwitchJavaScript開發(fā)

2020-12-08 08:09:49

SVG圖標(biāo)Web

2021-03-05 18:04:15

JavaScript循環(huán)代碼
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)