時間:2023-10-02 17:42:02 | 來源:網(wǎng)站運(yùn)營
時間:2023-10-02 17:42:02 來源:網(wǎng)站運(yùn)營
[HTML]CSS基礎(chǔ)教程-1:簡介.css
。 通過使用 CSS 可以大大提升網(wǎng)頁開發(fā)的工作效率 在教程中,您會學(xué)到如何使用 CSS 同時控制多重網(wǎng)頁的樣式和布局。;
結(jié)束,聲明總以大括號 {}
括起來p {color:red;text-align:center;}
為了讓CSS可讀性更強(qiáng),你可以每行只描述一個屬性p{ color:red; text-align:center;}
CSS 注釋 注釋是用來解釋你的代碼,并且可以隨意編輯它,瀏覽器會忽略它。/*
開始, 以*/
結(jié)束, 實(shí)例如下/*這是個注釋*/p{ text-align:center; /*這是另一個注釋*/ color:black; font-family:arial;}
Id
和Class
<.....id="..." class="...">
#para1{ text-align:center; color:red;}
提示:ID屬性盡量以字母開頭,數(shù)字開頭的ID在 Mozilla/Firefox 瀏覽器中不起作用。.center {text-align:center;}
你也可以指定特定的 HTML 元素使用 class。p.center {text-align:center;}
多個 class 選擇器可以使用空格分開..center { text-align:center; }.color { color:#ff0000; }
<link>
標(biāo)簽鏈接到樣式表。 <link>
標(biāo)簽在(文檔的)頭部:<head><link rel="stylesheet" type="text/css" href="mystyle.css"></head>
瀏覽器會從文件 mystyle.css
中讀到樣式聲明,并根據(jù)它來格式文檔。hr {color:sienna;}p {margin-left:20px;}body {background-image:url("/images/back40.gif");}
提示:不要在屬性值與單位之間留有空格(如:"margin-left: 20 px" ),正確的寫法是 "margin-left: 20px" 。)(是20px不是20 px)<style>
標(biāo)簽在文檔頭部定義內(nèi)部樣式表,就像這樣:<head><style>hr {color:sienna;}p {margin-left:20px;}body {background-image:url("images/back40.gif");}</style></head>
<p style="color:sienna;margin-left:20px">這是一個段落。</p>
h3{ color:red; text-align:left; font-size:8pt;}
而內(nèi)部樣式表擁有針對 h3 選擇器的兩個屬性:h3{ text-align:right; font-size:20pt;}
假如擁有內(nèi)部樣式表的這個頁面同時與外部樣式表鏈接,那么 h3 得到的樣式是:color:red;text-align:right;font-size:20pt;
即顏色屬性將被繼承于外部樣式表,而文字排列(text-alignment)和字體尺寸(font-size)會被內(nèi)部樣式表中的規(guī)則取代。h3 { color:blue;}
實(shí)例<head> <!-- 外部樣式 style.css --> <link rel="stylesheet" type="text/css" href="style.css"/> <!-- 設(shè)置:h3{color:blue;} --> <style type="text/css"> /* 內(nèi)部樣式 */ h3{color:green;} </style></head><body> <h3>顯示綠色,是內(nèi)部樣式</h3></body>
注意:如果外部樣式放在內(nèi)部樣式的后面,則外部樣式將覆蓋內(nèi)部樣式,實(shí)例如下<head> <!-- 設(shè)置:h3{color:blue;} --> <style type="text/css"> /* 內(nèi)部樣式 */ h3{color:green;} </style> <!-- 外部樣式 style.css --> <link rel="stylesheet" type="text/css" href="style.css"/></head><body> <h3>顯示藍(lán)色,是外部樣式</h3></body>
body {background-color:#b0c4de;}
CSS中,顏色值通常以以下方式定義:h1 {background-color:#6495ed;}p {background-color:#e0ffff;}div {background-color:#b0c4de;}
body {background-image:url('paper.gif');}
body{background-image:url('gradient2.png');}
如果圖像只在水平方向平鋪 (repeat-x), 頁面背景會更好些:body{background-image:url('gradient2.png');background-repeat:repeat-x;}
body{background-image:url('img_tree.png');background-repeat:no-repeat;}
以上實(shí)例中,背景圖像與文本顯示在同一個位置,為了讓頁面排版更加合理,不影響文本的閱讀,我們可以改變圖像的位置。body{background-image:url('img_tree.png');background-repeat:no-repeat;background-position:right top;}
body {background:#ffffff url('img_tree.png') no-repeat right top;}
當(dāng)使用簡寫屬性時,屬性值的順序?yàn)椋?標(biāo)簽 | 描述 |
---|---|
background | 簡寫屬性,作用是將背景屬性設(shè)置在一個聲明中。 |
background-attachment | 背景圖像是否固定或者隨著頁面的其余部分滾動。 |
background-color | 設(shè)置元素的背景顏色。 |
background-image | 把圖像設(shè)置為背景。 |
background-position | 設(shè)置背景圖像的起始位置。 |
background-repeat | 設(shè)置背景圖像是否及如何重復(fù)。 |
body {color:red;}h1 {color:#00ff00;}h2 {color:rgb(255,0,0);}
h1 {text-align:center;}p.date {text-align:right;}p.main {text-align:justify;}
a {text-decoration:none;}
也可以這樣裝飾文字:h1 {text-decoration:overline;}h2 {text-decoration:line-through;}h3 {text-decoration:underline;
p.uppercase {text-transform:uppercase;}p.lowercase {text-transform:lowercase;}p.capitalize {text-transform:capitalize;}
p {text-indent:50px;}
屬性 | 描述 |
---|---|
color | 設(shè)置文本顏色 |
direction | 設(shè)置文本方向。 |
letter-spacing | 設(shè)置字符間距 |
line-height | 設(shè)置行高 |
text-align | 對齊元素中的文本 |
text-decoration | 向文本添加修飾 |
text-indent | 縮進(jìn)元素中文本的首行 |
text-shadow | 設(shè)置文本陰影 |
text-transform | 控制元素中的字母 |
unicode-bidi | 設(shè)置或返回文本是否被重寫 |
vertical-align | 設(shè)置元素的垂直對齊 |
white-space | 設(shè)置元素中空白的處理方式 |
word-spacing | 設(shè)置字間距 |
Generic family | 字體系列 | 說明 |
---|---|---|
Serif | Times New Roman Georgia | Serif字體中字符在行的末端擁有額外的裝飾 |
Sans-serif | Arial Verdana | "Sans"是指無 - 這些字體在末端沒有額外的裝飾 |
Monospace | Courier New Lucida Console | 所有的等寬字符具有相同的寬度 |
p{font-family:"Times New Roman", Times, serif;}
p.normal {font-style:normal;}p.italic {font-style:italic;}p.oblique {font-style:oblique;}
<h1>
- <h6>
表示標(biāo)題和<p>
表示段落:關(guān)鍵詞:教程,基礎(chǔ)
客戶&案例
營銷資訊
關(guān)于我們
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。