web前端入門到實戰(zhàn):css3基礎(chǔ)-選擇器+邊框與圓角+背景與漸變

Css3****選擇器相關(guān):

section > div直接子元素選擇器

div + article相鄰兄弟選擇器(在元素之后出現(xiàn))

div ~ article通用兄弟選擇器(在元素之后出現(xiàn))


屬性選擇器:

a[href] {
    text-decoration: none;
}
a[href="#"] {
    color: #f00;
}
/*包含two且屬性值用空格分隔:*/
a[class~="two"] {
    color: #ff0;
}
/*屬性的第一個值以#開頭:*/
a[href^="#"] {
    color: #0f0;
}
/*以#結(jié)尾:*/
a[href$="#"] {
    color: #00f;
}
/*包含#:*/
a[href*="#"] {
    color: #0ff;
}
/*第一個屬性值以#-開頭:*/
a[href|="#"] {
    color: #f0f;
}
專門建立的學(xué)習(xí)Q-q-u-n: 784783012 ,分享學(xué)習(xí)的方法和需要注意的小細(xì)節(jié)酷勺,不停更新最新的教程和學(xué)習(xí)技巧
(從零基礎(chǔ)開始到前端項目實戰(zhàn)教程笋熬,學(xué)習(xí)工具汤徽,全棧開發(fā)學(xué)習(xí)路線以及規(guī)劃)

UI元素偽類:

Input:disabled

Input:enabled

Input:checked


div:first-child匹配屬于其父元素的第1個子元素且是div铅辞,計數(shù)時不分類型谋国,顯示時分類型

div:last-child匹配屬于其父元素的最后1個子元素且是div葵礼,計數(shù)時不分類型号阿,顯示時分類型div:nth-child(2) 匹配屬于其父元素的第n個子元素且是div,計數(shù)時不分類型鸳粉,顯示時分類型div:nth-lat-child(2) 匹配屬于其父元素的第n個子元素且是div扔涧,計數(shù)時不分類型,顯示時分類型


n匹配下標(biāo)届谈,從0開始計算:

li:nth-child(2n) 雙數(shù)

li:nth-child(2n+1) 單數(shù)

li:nth-child(n+4)

li:nth-child(odd) 奇數(shù)枯夜,下標(biāo)從1開始計算

li:nth-child(even) 偶數(shù),下標(biāo)從1開始計算

li:nth-last-child(3) 倒數(shù)第3個

article:only-child 屬于父元素的唯一元素艰山,且是article(沒有任何其他子元素)


div:nth-of-type(2) 匹配屬于其父元素的第2個子元素且是div湖雹,計數(shù)時分類型

div:nth-last-of-type(2)

div:first-of-type div:last-of-type

article:only-of-type 屬于父元素的唯一article元素(可以有其他類型的子元素)


div:empty 沒有子元素的div元素(包括文本也沒有)

a:not(:last-of-type) 不是最后一個a子元素


id選擇器權(quán)重大于屬性選擇器

.red > [class=”red”]


Css偽元素:

div::selection 文本被選中后的樣式

::-moz-selection 火狐


Css3****邊框與圓角:

四個值按照順時針方向來

Border-radius兼容性寫法:

-webkit-border-radius: 50%;
       -moz-border-radius: 50%;
        -ms-border-radius: 50%;
         -o-border-radius: 50%;
            border-radius: 50%;

box-shadow水平偏移 垂直偏移 模糊 擴(kuò)展 顏色 內(nèi)部

box-shadow: 50px 30px 0px 0px yellow inset;

border-image-repeat:stretch(拉伸)/repeat(重復(fù))/round(鋪滿)/initial/inherit



border-image-source: url("border.jpg");
    border-image-slice: 50%;/*圖像邊界向內(nèi)偏移*/
    border-image-width: 50%;/*圖像邊界的寬度*/
    border-image-outset: 2; /*在邊框外部繪制*/
    border-image-repeat: repeat; 

css3****背景與漸變:

背景繪制區(qū)域(顯示范圍)

background-clip: border-box;
background-clip: padding-box;
background-clip: content-box;

背景圖像定位(起始位置,原點位置程剥,與偏移搭配使用)

background-origin: border-box;
background-origin: padding-box;
background-origin: content-box;
background-position:10px 10px; /*與偏移搭配使用*/

background-size只寫一個值劝枣,第二個默認(rèn)是auto,根據(jù)比例等比縮放

background-size: contain; /*等比縮放到某一邊達(dá)到容器邊緣*/
background-size: cover;/*等比縮放填滿容器*/
background-size: 800px 500px;
background-size: 800px;
background-size: 50% 50%;
background-size: 50%;
background-size: 100% 100%;
background-size: 100%;

background-image多重背景织鲸,前面的會覆蓋后面的

background-image: url('bg2.png'), url('bg1.jpg');

demo:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>background-image</title>
    <style type="text/css"> div{ width:300px; height:300px; background:url(1.jpg) no-repeat center top,
            url(2.jpg) no-repeat center 100px,
            url(3.jpg) no-repeat center 200px; margin:0 auto;
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

默認(rèn)從上到下漸變:

div {
    width: 800px; height: 500px;
    background: -webkit-linear-gradient(red, blue);
    background:    -moz-linear-gradient(red, blue);
    background:      -o-linear-gradient(red, blue);
    background:         linear-gradient(red, blue);
}

從左到右漸變

div {
    width: 800px; height: 500px;
    background: -webkit-linear-gradient(left, red , blue);
    background:    -moz-linear-gradient(right, red, blue);
    background:      -o-linear-gradient(right, red, blue);
    background:         linear-gradient(to right, red , blue);
}

左上角開始的對角線漸變


div {
    width: 800px; height: 500px;
    background: -webkit-linear-gradient(       left top, red, yellow, blue);
    background:    -moz-linear-gradient(   right bottom, red, yellow, blue);
    background:      -o-linear-gradient(   right bottom, red, yellow, blue);
    background:         linear-gradient(to right bottom, red, yellow, blue);
}

角度控制方向

角度漸變是水平線和漸變線之間的角度舔腾,0deg是從下到上,90度是從左到右

div {
    width: 800px; height: 500px;
    background: -webkit-linear-gradient(135deg, red, yellow, blue);
    background:    -moz-linear-gradient(135deg, red, yellow, blue);
    background:      -o-linear-gradient(135deg, red, yellow, blue);
    background:         linear-gradient(135deg, red, yellow, blue);
}
專門建立的學(xué)習(xí)Q-q-u-n: 784783012 搂擦,分享學(xué)習(xí)的方法和需要注意的小細(xì)節(jié)稳诚,不停更新最新的教程和學(xué)習(xí)技巧
(從零基礎(chǔ)開始到前端項目實戰(zhàn)教程,學(xué)習(xí)工具瀑踢,全棧開發(fā)學(xué)習(xí)路線以及規(guī)劃)

漸變具體位置控制

div {
    width: 800px; height: 500px;
    background: -webkit-linear-gradient(90deg, red 10%, orange 15%, yellow 20%, green 50%, blue 70%, indigo 80%, violet 100%);
    background:    -moz-linear-gradient(90deg, red 10%, orange 15%, yellow 20%, green 50%, blue 70%, indigo 80%, violet 100%);
    background:      -o-linear-gradient(90deg, red 10%, orange 15%, yellow 20%, green 50%, blue 70%, indigo 80%, violet 100%);
    background:         linear-gradient(90deg, red 10%, orange 15%, yellow 20%, green 50%, blue 70%, indigo 80%, violet 100%);
}

透明色漸變

div {
    width: 800px; height: 500px;
    background: -webkit-linear-gradient(90deg, rgba(255, 0, 0, 0), rgba(255, 0, 0, 1));
    background:    -moz-linear-gradient(90deg, rgba(255, 0, 0, 0), rgba(255, 0, 0, 1));
    background:      -o-linear-gradient(90deg, rgba(255, 0, 0, 0), rgba(255, 0, 0, 1));
    background:         linear-gradient(90deg, rgba(255, 0, 0, 0), rgba(255, 0, 0, 1));
}

重復(fù)漸變

div {
    width: 800px; height: 500px;
    background: -webkit-repeating-linear-gradient(90deg, red 0%, blue 10%, red 20%);
    background:    -moz-repeating-linear-gradient(90deg, red 0%, blue 10%, red 20%);
    background:      -o-repeating-linear-gradient(90deg, red 0%, blue 10%, red 20%);
    background:         repeating-linear-gradient(90deg, red 0%, blue 10%, red 20%);
}

徑向漸變扳还,從內(nèi)到外


div {
    width: 800px; height: 500px;
    background: -webkit-radial-gradient(red, blue);
    background:    -moz-radial-gradient(red, blue);
    background:      -o-radial-gradient(red, blue);
    background:         radial-gradient(red, blue);
}

圓形漸變

div {
    width: 800px; height: 500px;
    background: -webkit-radial-gradient(circle, red, blue);
    background:    -moz-radial-gradient(circle, red, blue);
    background:      -o-radial-gradient(circle, red, blue);
    background:         radial-gradient(circle, red, blue);
}

橢圓形漸變

div {
    width: 800px; height: 500px;
    background: -webkit-radial-gradient(ellipse, red, blue);
    background:    -moz-radial-gradient(ellipse, red, blue);
    background:      -o-radial-gradient(ellipse, red, blue);
    background:         radial-gradient(ellipse, red, blue);
}

漸變從圓心到最近邊

div.closest-side {
    width: 300px; height: 200px; margin: 50px;
    background: -webkit-radial-gradient(30% 70%, circle closest-side, red, blue);
    background:    -moz-radial-gradient(30% 70%, circle closest-side, red, blue);
    background:      -o-radial-gradient(30% 70%, circle closest-side, red, blue);
    background:         radial-gradient(30% 70%, circle closest-side, red, blue);
}

漸變從圓心到最遠(yuǎn)邊

專門建立的學(xué)習(xí)Q-q-u-n: 784783012 ,分享學(xué)習(xí)的方法和需要注意的小細(xì)節(jié)橱夭,不停更新最新的教程和學(xué)習(xí)技巧
(從零基礎(chǔ)開始到前端項目實戰(zhàn)教程氨距,學(xué)習(xí)工具,全棧開發(fā)學(xué)習(xí)路線以及規(guī)劃)
div.farthest-side {
    width: 300px; height: 200px; margin: 50px;
    background: -webkit-radial-gradient(30% 70%, farthest-side, red, blue);
    background:    -moz-radial-gradient(30% 70%, farthest-side, red, blue);
    background:      -o-radial-gradient(30% 70%, farthest-side, red, blue);
    background:         radial-gradient(30% 70%, farthest-side, red, blue);
}

漸變從圓心到最近角

div.closest-corner {
    width: 300px; height: 200px; margin: 50px;
    background: -webkit-radial-gradient(30% 70%, closest-corner, red, blue);
    background:    -moz-radial-gradient(30% 70%, closest-corner, red, blue);
    background:      -o-radial-gradient(30% 70%, closest-corner, red, blue);
    background:         radial-gradient(30% 70%, closest-corner, red, blue);
}

漸變從圓心到最遠(yuǎn)角

div.farthest-corner {
    width: 300px; height: 200px; margin: 50px;
    background: -webkit-radial-gradient(30% 70%, farthest-corner, red, blue);
    background:    -moz-radial-gradient(30% 70%, farthest-corner, red, blue);
    background:      -o-radial-gradient(30% 70%, farthest-corner, red, blue);
    background:         radial-gradient(30% 70%, farthest-corner, red, blue);
}

IE漸變從上到下

div {
    width: 800px;
    height: 500px;
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff0000', endColorstr='#0000ff',GradientType=0 );
}

IE漸變從左到右


div {
    width: 800px;
    height: 500px;
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff0000', endColorstr='#0000ff',GradientType=1 );
}

Demo:


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>線性漸變 - 特殊案例</title>
<style type="text/css"> div { width: 800px; height: 500px; background: #abcdef; background-size: 50px 50px; background-image: -webkit-gradient(linear, 0 0, 100% 100%, color-stop(.25, #555), color-stop(.25, transparent), to(transparent)),
        -webkit-gradient(linear, 0 100%, 100% 0, color-stop(.25, #555), color-stop(.25, transparent), to(transparent)),
        -webkit-gradient(linear, 0 0, 100% 100%, color-stop(.75, transparent), color-stop(.75, #555)),
        -webkit-gradient(linear, 0 100%, 100% 0, color-stop(.75, transparent), color-stop(.75, #555)); background-image: -moz-linear-gradient(45deg, #555 25%, transparent 25%, transparent),
        -moz-linear-gradient(-45deg, #555 25%, transparent 25%, transparent),
        -moz-linear-gradient(45deg, transparent 75%, #555 75%),
        -moz-linear-gradient(-45deg, transparent 75%, #555 75%); background-image: -o-linear-gradient(45deg, #555 25%, transparent 25%, transparent),
        -o-linear-gradient(-45deg, #555 25%, transparent 25%, transparent),
        -o-linear-gradient(45deg, transparent 75%, #555 75%),
        -o-linear-gradient(-45deg, transparent 75%, #555 75%); background-image: linear-gradient(45deg, #555 25%, transparent 25%, transparent),
        linear-gradient(-45deg, #555 25%, transparent 25%, transparent),
        linear-gradient(45deg, transparent 75%, #555 75%),
        linear-gradient(-45deg, transparent 75%, #555 75%);
}
</style>
</head>
<body>
<div></div>
</body>
</html>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末棘劣,一起剝皮案震驚了整個濱河市俏让,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖首昔,帶你破解...
    沈念sama閱讀 217,734評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件寡喝,死亡現(xiàn)場離奇詭異,居然都是意外死亡勒奇,警方通過查閱死者的電腦和手機(jī)预鬓,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來赊颠,“玉大人格二,你說我怎么就攤上這事【匏埃” “怎么了蟋定?”我有些...
    開封第一講書人閱讀 164,133評論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長草添。 經(jīng)常有香客問我驶兜,道長,這世上最難降的妖魔是什么远寸? 我笑而不...
    開封第一講書人閱讀 58,532評論 1 293
  • 正文 為了忘掉前任抄淑,我火速辦了婚禮,結(jié)果婚禮上驰后,老公的妹妹穿的比我還像新娘肆资。我一直安慰自己,他們只是感情好灶芝,可當(dāng)我...
    茶點故事閱讀 67,585評論 6 392
  • 文/花漫 我一把揭開白布郑原。 她就那樣靜靜地躺著,像睡著了一般夜涕。 火紅的嫁衣襯著肌膚如雪犯犁。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,462評論 1 302
  • 那天女器,我揣著相機(jī)與錄音酸役,去河邊找鬼。 笑死驾胆,一個胖子當(dāng)著我的面吹牛涣澡,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播丧诺,決...
    沈念sama閱讀 40,262評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼入桂,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了驳阎?” 一聲冷哼從身側(cè)響起抗愁,我...
    開封第一講書人閱讀 39,153評論 0 276
  • 序言:老撾萬榮一對情侶失蹤惕艳,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后驹愚,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,587評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡劣纲,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,792評論 3 336
  • 正文 我和宋清朗相戀三年逢捺,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片癞季。...
    茶點故事閱讀 39,919評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡劫瞳,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出绷柒,到底是詐尸還是另有隱情志于,我是刑警寧澤,帶...
    沈念sama閱讀 35,635評論 5 345
  • 正文 年R本政府宣布废睦,位于F島的核電站伺绽,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏嗜湃。R本人自食惡果不足惜奈应,卻給世界環(huán)境...
    茶點故事閱讀 41,237評論 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望购披。 院中可真熱鬧杖挣,春花似錦、人聲如沸刚陡。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,855評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽筐乳。三九已至歌殃,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間哥童,已是汗流浹背挺份。 一陣腳步聲響...
    開封第一講書人閱讀 32,983評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留贮懈,地道東北人匀泊。 一個月前我還...
    沈念sama閱讀 48,048評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像朵你,于是被迫代替她去往敵國和親各聘。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,864評論 2 354

推薦閱讀更多精彩內(nèi)容