Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
本章目標(biāo):
Cascading Style Sheet 級(jí)聯(lián)樣式表。 表現(xiàn)HTML或XHTML文件樣式的計(jì)算機(jī)語(yǔ)言。 包括對(duì)字體、顏色、邊距、高度、寬度、背景圖片、網(wǎng)頁(yè)定位等設(shè)定
在這里插入圖片描述
說(shuō)明:
在這里插入圖片描述
CSS1.0 讀者可以從其他地方去使用自己喜歡的設(shè)計(jì)樣式去繼承性地使用樣式;
CSS2.0 融入了DIV+CSS的概念,提出了HTML結(jié)構(gòu)與CSS樣式表的分離
CSS2.1 融入了更多高級(jí)的用法,如浮動(dòng),定位等。
CSS3.0 它包括了CSS2.1下的所有功能,是目前最新的版本,它向著模塊化的趨勢(shì)發(fā)展,又加了很多使用的新技術(shù),如字體、多背景、圓角、陰影、動(dòng)畫(huà)等高級(jí)屬性,但是它需要高級(jí)瀏覽器的支持。
由于現(xiàn)在IE 6、IE 7使用比例已經(jīng)很少,對(duì)市場(chǎng)企業(yè)進(jìn)行調(diào)研發(fā)現(xiàn)使用CSS3的頻率大幅增加,學(xué)習(xí)CSS3已經(jīng)成為一種趨勢(shì),因此本書(shū)會(huì)講解最新的CSS3版本
本課程中主要講解css2.1和css3
CSS的優(yōu)勢(shì)
在這里插入圖片描述
Style標(biāo)簽
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
鏈接式與導(dǎo)入式的區(qū)別
CSS樣式優(yōu)先級(jí)
行內(nèi)樣式>內(nèi)部樣式表>外部樣式表
就近原則:越接近標(biāo)簽的樣式優(yōu)先級(jí)越高
【學(xué)員練習(xí)】 使用標(biāo)題標(biāo)簽和段落標(biāo)簽制作李白的詩(shī)《望廬山瀑布》,詩(shī)正文字體顏色為綠色,字體大小為14p
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
小結(jié)
基本選擇器的優(yōu)先級(jí)
ID選擇器>類(lèi)選擇器>標(biāo)簽選擇
標(biāo)簽選擇器是否也遵循“就近原則”? 不遵循,無(wú)論是哪種方式引入CSS樣式,一般都遵循ID選擇器 > class類(lèi)選擇器 > 標(biāo)簽選擇器的優(yōu)先級(jí)
在這里插入圖片描述
在這里插入圖片描述
后代選擇器兩個(gè)選擇符之間必須要以空格隔開(kāi),中間不能有任何其他的符號(hào)插入
在這里插入圖片描述
在這里插入圖片描述
添加圖片注釋?zhuān)怀^(guò) 140 字(可選)
CSS樣式表是一個(gè)序列通用字符集,傳輸和存儲(chǔ)過(guò)程中,這些字符必須由支持 US-ASCII(例如 UTF-8, ISO 8859-x, SHIFT JIS 等)字符編碼方式編譯
When a style sheet is embedded in another document, such as in the STYLE element or "style" attribute of HTML, the style sheet shares the character encoding of the whole document.
當(dāng)樣式出現(xiàn)在其它文檔,如 HTML 的 STYLE 標(biāo)簽或標(biāo)簽屬性 "style",樣式的編碼由文檔的決定。
When a style sheet resides in a separate file, user agents must observe the following priorities when determining a style sheet's character encoding (from highest priority to lowest):
An HTTP "charset" parameter in a "Content-Type" field (or similar parameters in other protocols)BOM and/or [@charset ]()or other metadata from the linking mechanism (if any)charset of referring style sheet or document (if any)Assume UTF-8
文檔外鏈樣式表的編碼可以由以下各項(xiàng)按照由高到低的優(yōu)先級(jí)順序決定:
Authors using an [@charset ]() rule must place the rule at the very beginning of the style sheet, preceded by no characters. (If a byte order mark is appropriate for the encoding used, it may precede the [@charset ]() rule.)
[@charset ]() must be written literally, i.e., the 10 characters '[@charset ]() "' (lowercase, no backslash escapes), followed by the encoding name, followed by '";'.
推薦:
@charset "UTF-8";
.jdc{}
不推薦:
/**
* @desc File Info
* @author Author Name
* @date 2015-10-10
*/
/* @charset規(guī)則不在文件首行首個(gè)字符開(kāi)始 */
@charset "UTF-8";
.jdc{}
@CHARSET "UTF-8";
/* @charset規(guī)則沒(méi)有用小寫(xiě) */
.jdc{}
/* 無(wú)@charset規(guī)則 */
.jdc{}
更多關(guān)于樣式編碼:CSS style sheet representation
樣式書(shū)寫(xiě)一般有兩種:一種是緊湊格式 (Compact)
.jdc{ display: block;width: 50px;}
一種是展開(kāi)格式(Expanded)
.jdc{
display: block;
width: 50px;
}
團(tuán)隊(duì)約定
統(tǒng)一使用展開(kāi)格式書(shū)寫(xiě)樣式
樣式選擇器,屬性名,屬性值關(guān)鍵字全部使用小寫(xiě)字母書(shū)寫(xiě),屬性字符串允許使用大小寫(xiě)。
/* 推薦 */
.jdc{
display:block;
}
/* 不推薦 */
.JDC{
DISPLAY:BLOCK;
}
/* 推薦 */
.jdc {}
.jdc li {}
.jdc li p{}
/* 不推薦 */
*{}
#jdc {}
.jdc div{}
統(tǒng)一使用四個(gè)空格進(jìn)行代碼縮進(jìn),使得各編輯器表現(xiàn)一致(各編輯器有相關(guān)配置)
.jdc {
width: 100%;
height: 100%;
}
每個(gè)屬性聲明末尾都要加分號(hào);
.jdc {
width: 100%;
height: 100%;
}
左括號(hào)與類(lèi)名之間一個(gè)空格,冒號(hào)與屬性值之間一個(gè)空格
推薦:
.jdc {
width: 100%;
}
不推薦:
.jdc{
width:100%;
}
逗號(hào)分隔的取值,逗號(hào)之后一個(gè)空格
推薦:
.jdc {
box-shadow: 1px 1px 1px #333, 2px 2px 2px #ccc;
}
不推薦:
.jdc {
box-shadow: 1px 1px 1px #333,2px 2px 2px #ccc;
}
為單個(gè)css選擇器或新申明開(kāi)啟新行
推薦:
.jdc,
.jdc_logo,
.jdc_hd {
color: #ff0;
}
.nav{
color: #fff;
}
不推薦:
.jdc,jdc_logo,.jdc_hd {
color: #ff0;
}.nav{
color: #fff;
}
顏色值 rgb() rgba() hsl() hsla() rect() 中不需有空格,且取值不要帶有不必要的 0
推薦:
.jdc {
color: rgba(255,255,255,.5);
}
不推薦:
.jdc {
color: rgba( 255, 255, 255, 0.5 );
}
屬性值十六進(jìn)制數(shù)值能用簡(jiǎn)寫(xiě)的盡量用簡(jiǎn)寫(xiě)
推薦:
.jdc {
color: #fff;
}
不推薦:
.jdc {
color: #ffffff;
}
不要為 0 指明單位
推薦:
.jdc {
margin: 0 10px;
}
不推薦:
.jdc {
margin: 0px 10px;
}
css屬性值需要用到引號(hào)時(shí),統(tǒng)一使用單引號(hào)
/* 推薦 */
.jdc {
font-family: 'Hiragino Sans GB';
}
/* 不推薦 */
.jdc {
font-family: "Hiragino Sans GB";
}
建議遵循以下順序:
.jdc {
display: block;
position: relative;
float: left;
width: 100px;
height: 100px;
margin: 0 10px;
padding: 20px 0;
font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
color: #333;
background: rgba(0,0,0,.5);
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-o-border-radius: 10px;
-ms-border-radius: 10px;
border-radius: 10px;
}
mozilla官方屬性順序推薦
CSS3 瀏覽器私有前綴在前,標(biāo)準(zhǔn)前綴在后
.jdc {
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-o-border-radius: 10px;
-ms-border-radius: 10px;
border-radius: 10px;
}
更多關(guān)于瀏覽器私有前輟寫(xiě)法:#Vendor-specific extensions
Google Code Guide
SS(層疊樣式表)是一種用于描述HTML或XML(包括各種XML方言,如SVG或XHTML)文檔的視覺(jué)表現(xiàn)的樣式語(yǔ)言。CSS描述了元素應(yīng)該如何在屏幕、紙張、語(yǔ)音或其他媒體上顯示。本文將深入探討CSS的核心概念和語(yǔ)法,為初學(xué)者和有經(jīng)驗(yàn)的開(kāi)發(fā)者提供一個(gè)參考。
選擇器是CSS中的基礎(chǔ)概念,它們用于指定我們想要樣式化的HTML元素。
p {
color: black;
}
.error {
color: red;
}
#unique-element {
color: blue;
}
input[type="text"] {
background-color: #f0f0f0;
}
a:hover {
text-decoration: underline;
}
組合器描述了不同選擇器之間的關(guān)系。
article p {
line-height: 1.6;
}
ul > li {
list-style-type: square;
}
h2 + p {
margin-top: 0;
}
h2 ~ p {
color: #333;
}
偽元素用于樣式化元素的特定部分。
p::first-line {
font-weight: bold;
}
CSS屬性定義了如何對(duì)元素進(jìn)行樣式化,而值則指定了屬性的外觀或行為。
width: 100px;
height: 50vh; /* 視口高度的50% */
background-color: #ff0000;
color: rgb(0, 255, 0);
border-color: rgba(0, 0, 255, 0.5);
font-family: 'Arial', sans-serif;
text-align: center;
text-decoration: underline;
margin: 10px 5px;
padding: 20px;
border-style: solid;
border-width: 1px;
border-color: #000;
.container {
display: flex;
justify-content: space-between;
}
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
.absolute-element {
position: absolute;
top: 10px;
right: 10px;
}
使用媒體查詢(xún)可以創(chuàng)建響應(yīng)不同屏幕尺寸的樣式。
@media (max-width: 600px) {
.container {
flex-direction: column;
}
}
CSS是一個(gè)強(qiáng)大的樣式語(yǔ)言,它使得開(kāi)發(fā)者能夠創(chuàng)建精美、響應(yīng)式的網(wǎng)頁(yè)。通過(guò)理解并掌握CSS的選擇器、屬性、布局等核心概念和語(yǔ)法,前端工程師可以有效地設(shè)計(jì)和實(shí)現(xiàn)用戶(hù)界面。隨著CSS3和后續(xù)版本的不斷發(fā)展,CSS的能力也在不斷增強(qiáng),為前端開(kāi)發(fā)帶來(lái)了更多的可能性。
*請(qǐng)認(rèn)真填寫(xiě)需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。