經常使用CSS樣式1:文本樣式

#css基本語法及頁面引用
##css基本語法
css的定義方法是:css

選擇器 { 屬性:值; 屬性:值; 屬性:值;}ide

選擇器是將樣式和頁面元素關聯起來的名稱,屬性是但願設置的樣式屬性每一個屬性有一個或多個值。代碼示例:字體

div{ width:100px; height:100px; color:red }

##css頁面引入方法:
一、外聯式:經過link標籤,連接到外部樣式表到頁面中。code

<link rel="stylesheet" type="text/css" href="css/main.css">

二、嵌入式:經過style標籤,在網頁上建立嵌入的樣式表。orm

<style type="text/css">
    div{ width:100px; height:100px; color:red }
    ......
</style>

三、內聯式:經過標籤的style屬性,在標籤上直接寫樣式。it

<div style="width:100px; height:100px; color:red ">......</div>

##css文本設置
經常使用的應用文本的css樣式:io

  • color 設置文字的顏色,如: color:red;
  • font-size 設置文字的大小,如:font-size:12px;
  • font-family 設置文字的字體,如:font-family:'微軟雅黑';
  • font-style 設置字體是否傾斜,如:font-style:'normal';設置不傾斜,font-style:'italic';設置文字傾斜
  • font-weight 設置文字是否加粗,如:font-weight:bold; 設置加粗 font-weight:normal設置不加粗
  • font 同時設置文字的幾個屬性,寫的順序有兼容問題,建議按照以下順序寫: font:是否加粗 字號/行高 字體;如:font:normal 12px/36px '微軟雅黑';
  • line-height 設置文字的行高,如:line-height:24px;
  • text-decoration 設置文字的下劃線,如:text-decoration:none; 將文字下劃線去掉
  • text-indent 設置文字首行縮進,如:text-indent:24px; 設置文字首行縮進24px
  • text-align 設置文字水平對齊方式,如text-align:center 設置文字水平居中
相關文章
相關標籤/搜索