CSS文本属性

文本对齐属性(text-align)

这个属性用来设定文本的对齐方式。有以下值:
• left (居左,缺省值) 
• right (居右) 
• center (居中) 
• justify (两端对齐)

[html]  view plain  copy
 
  1. <html>  
  2. <head>  
  3. <title>文本对齐属性 text-aligntitle>  
  4. <style type="text/css">  
  5. .p1{text-align:left}  
  6. .p2 {text-align:right}  
  7. .p3{text-align:center}  
  8.   
  9. style>  
  10. head>  
  11.   
  12. <body>  
  13.   
  14. <p class = "p1">这段的本文对齐属性(text-align)值为居左。p>  
  15. <p class = "p2">这段的本文对齐属性(text-align)值为居右。p>  
  16. <p class = "p3">这段的本文对齐属性(text-align)值为居中。p>  
  17.   
  18.   
  19. body>  
  20. html>  

文本修饰属性(text-decoration)
这个属性主要设定文本划线的属性。有以下值:
• none (无,缺省值) 
• underline (下划线) 
• overline (上划线) 

• line-through (当中划线)

[html]  view plain  copy
 
  1. <html>  
  2. <head>  
  3. <title>文本修饰属性 text-decorationtitle>  
  4. <style type="text/css">  
  5. .p1{text-decoration: none}  
  6. .p2 {text-decoration: underline}  
  7. .p3{text-decoration: line-through}  
  8. .p4 {text-decoration:overline}  
  9. style>  
  10. head>  
  11.   
  12. <body>  
  13. <p class = "p1">文本修饰属性(text-decoration)的缺省值是none。p>  
  14. <p class = "p2">这段的文本修饰属性(text-decoration)值是underline。p>  
  15. <p class = "p3">这段的文本修饰属性(text-decoration)值是line-through。p>  
  16. <p class = "p4">这段的文本修饰属性(text-decoration)值是overline。p>  
  17.   
  18. body>  
  19. html>  

文本缩进属性(text-indent)
这个属性设定文本首行缩进。其值有以下设定方法:
• length (长度,可以用绝对单位(cm, mm, in, pt, pc)或者相对单位 (em, ex, px)) 
• percentage (百分比,相当于父对象宽度的百分比)

[html]  view plain  copy
 
  1. <html>  
  2. <head>  
  3. <title>文本缩进属性 text-indenttitle>  
  4. <style type="text/css">  
  5. .p1 {text-indent: 2em} /*2em表示缩进两个字符*/  
  6. .d1 {width:300px}  
  7. .p2 {text-indent:50%}  
  8. style>  
  9. head>  
  10.   
  11. <body>  
  12. <p>下面两端都设定CSS文本缩进属性(text-indent),第一段用长度方法设值,第二段用百分比方法设值。p>  
  13.   
  14. <p class = "p1">芙蓉姐姐说道:“我那妖媚性感的外形和冰清玉洁的气质让我无论走到哪里都会被众人的目光无情地揪出来。我总是很焦点。我那张耐看的脸,配上那副火爆得让男人流鼻血的身体,就注定了我前半生的悲剧。”p>  
  15.   
  16. <div class = "d1">  
  17. <p class = p2>芙蓉姐姐说道:“我那妖媚性感的外形和冰清玉洁的气质让我无论走到哪里都会被众人的目光无情地揪出来。我总是很焦点。我那张耐看的脸,配上那副火爆得让男人流鼻血的身体,就注定了我前半生的悲剧。”p>  
  18. div>  
  19.   
  20. body>  
  21. html>  


行高属性(line-height)

这个属性设定每行之间的距离。其值有以下设定方法:
• normal (缺省值) 
• length (长度,可以用绝对单位(cm, mm, in, pt,pc)或者相对单位 (em, ex, px)) 

• percentage (百分比,相当于父对象高度的百分比)

在font属性里缩写line-height值紧跟着font-size值,使用斜杠隔开/

[html]  view plain  copy
 
  1. <html>  
  2. <head>  
  3. <title>行高属性 line-heighttitle>  
  4. <style type="text/css">  
  5. .p1 {line-height:30px}  
  6. .p2 {line-height:30px}  
  7. style>  
  8. head>  
  9.   
  10. <body>  
  11. <p class = "p1">这个段落的CSS行高属性(line-hight)值为30px,即每行之间的距离是30个像素。p>  
  12.   
  13. <p class = "p2">这个段落的CSS行高属性(line-hight)值为50px,即每行之间的距离是50个像素。p>  
  14.   
  15. body>  
  16. html>  

文字间距属性(letter-spacing)
这个属性用来设定文字之间的距离。
• normal (缺省值) 
• length (长度,可以用绝对单位(cm, mm, in, pt, pc)或者相对单位 (em, ex, px))

[html]  view plain  copy
 
  1. <html>  
  2. <head>  
  3. <title>文字间距属性 letter-spacingtitle>  
  4. <style type="text/css">  
  5. .p1 {letter-spacing: 3px}  
  6. style>  
  7. head>  
  8.   
  9. <body>  
  10.   
  11. <p>这段没有设置文字间距属性(letter-spacing)。p>  
  12. <p class = "p1">这段设定文字间距属性(letter-spacing)值为3像素。p>  
  13.   
  14. body>  
  15. html>  

颜色属性(color)

用颜色属性(color)可以改变文本的字体颜色。

[html]  view plain  copy
 
  1. .p1{color:gray}  

你可能感兴趣的:(js与前端)