【3-24】css樣式表分類、選取器、樣式屬性、格式布局

來源:互聯網
上載者:User

標籤:補充   htm   nowrap   sha   ext   idg   active   換行   優先   

一、css樣式表分類:

(一)內聯樣式表:代碼寫在標籤內的樣式表  控制精確 代碼重用性差  優先順序最高

格式:<p style="樣式屬性">內容</p>

 <div style="text-decoration:line-through;">第四格第三元</div>

 

(二)內嵌樣式表:將代碼寫在標籤<style type="text/css"></style>之間,此標籤一般寫在head之中

內嵌樣式表 代碼重用性好 沒有內聯精確 優先順序第二

格式:<style type="text/css">

.組名{樣式屬性}

</style>

(三)外部樣式表:把css寫在單獨的檔案中,尾碼名以.css命名

在<head>內用<link>標籤串連

格式:<link href="相對路徑" rel="stylesheet">

.div1 {    width:100px;    height:150px;    background-color:red;}    <link href="3-23練習.css" rel="stylesheet" />

二、選取器

1、class選取器

格式: 

.class名

{ 

屬性名稱: 屬性值; 

….}

2、ID選取器

格式:

 

#id名

{ 

屬性名稱: 屬性值;

 ….}

3、標籤選取器

格式:

某個html標籤{ 

屬性名稱:屬性值; 

…}

4、複合選取器

(1)並列複合:多選取器名 並用“,”隔開,適用於不同標籤並列

例:

.div3,.a1{    width:400px;    height:200px;    border:1px dashed black;}

(2)後代複合:使用空格隔開,適用於同一標籤不同層級 

例:

.div1 .b1 {    width:800px;    height:initial;    font-size:5px;    font-style:italic;    font-family:華文行楷;    font-weight:bold;    border: 1px solid black;}

三、樣式屬性

(一)格局大小:

width:寬;

height:高;

(二)背景屬性: (background)

色彩 :background-color:   ;

圖片 :background-image: url(相對路徑 );

平鋪方式 :background-repeat: no-repeat;

滾動 :background-attachment: fixed;(固定) scroll;(滾動)

圖片大小:background-size:像素;

位置 :background-position: left;(水平) top(垂直);

(三)字型屬性:(font)

大小 :font-size: 像素px;

顏色:color:    ;

字型:font-family:    ;

樣式 :font-style: oblique;(偏斜體) italic;(斜體) normal;(正常)

粗細 :font-weight: bold;(粗體) lighter;(細體) normal;(正常)

修飾 :text-decoration: underline;(底線) overline;(上劃線) line-through;(刪除線) blink;(閃爍)

變體 :font-variant: small-caps;(小型大寫字母) normal;(正常)

大小寫 :text-transform: capitalize;(首字母大寫) uppercase;(大寫) lowercase;(小寫) none;(無)

常用字型: (font-family)

(四)對齊對齊

對齊 :text-align: justify;(左右對齊) left;(靠左對齊) right;(靠右對齊) center;(置中)

垂直對齊 :vertical-align: baseline;(基準) sub;(下標) super;(下標) top; text-top; middle; bottom; text-bottom;

(需配合display:table-cell;使用)

縮排 :text-indent: 數值px;

行高 :line-height: normal;(正常) 

詞間距word-spacing: normal; 數值

空格white-space: pre;(保留) nowrap;(不換行)

顯示 :display:block;(塊) inline;(內嵌) list-item;(清單項目) run-in;(追加部分) compact;(緊湊) marker;(標記) table; inline-table; table-raw-group; table-header-group; table-footer-group; table-raw; table-column-group; table-column; table-cell; table-caption;(表格標題) 

(五)邊界邊框

 外邊界:margin:;順序:上右下左

內邊界:padding:;

邊框格式:border-style: dotted;(點線) dashed;(虛線) solid; double;(雙線) groove;(槽線) ridge;(脊狀) inset;(凹陷) outset;

邊框寬度:border-width:; 

邊框顏色:border-color:#;

和寫邊框:border:  border-width  border-style  border-color;

(六)列表方塊

序號映像:list-style-image: url(..);

有無列表序號:list-style:none;

類型:list-style-type: disc;(圓點) circle;(圓圈) square;(方塊) decimal;(數字) lower-roman;(小羅碼數字) upper-roman; lower-alpha; upper-alpha;

位置:list-style-position: outside;(外) inside;

(七)其他常用屬性

(1)display:none;--隱藏,不保留位置

visibility:hidden;--隱藏,保留位置

overfllow:scoll;--捲軸

透明:optacity:(0-1);

-moz-opacity:(0-1);

filter:alpha(opacity=0-100);

圓角:border-radius:像素;

陰影:box-shadow:像素(左位移)像素(右位移)像素(擴散度)

補充留用:

a:link /*超連結顯示文字格式*/

a:visited /*瀏覽過的連結文字格式*/

a:active /*按下連結的格式*/

a:hover /*滑鼠轉到連結*/

滑鼠游標樣式:

連結手指 CURSOR: hand

十字型 cursor:crosshair

箭頭朝下 cursor:s-resize

十字箭頭 cursor:move

箭頭朝右 cursor:move

加一問號 cursor:help

箭頭朝左 cursor:w-resize

箭頭朝上 cursor:n-resize

箭頭朝右上 cursor:ne-resize

箭頭朝左上 cursor:nw-resize

文字I型 cursor:text

箭頭斜右下 cursor:se-resize

箭頭斜左下 cursor:sw-resize

漏鬥 cursor:wait

游標圖案(IE6) p {cursor:url("游標檔案名稱.cur"),text;}

【3-24】css樣式表分類、選取器、樣式屬性、格式布局

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.