CSS背景

背景

屬性 描述
background 簡寫屬性沾谜,作用是將背景屬性設(shè)置在一個(gè)聲明中。
background-attachment 背景圖像是否固定或者隨著頁面的其余部分滾動(dòng)胀莹。
background-color 設(shè)置元素的背景顏色基跑。
background-image 把圖像設(shè)置為背景。
background-position 設(shè)置背景圖像的起始位置描焰。
background-repeat 設(shè)置背景圖像是否及如何重復(fù)媳否。

第一個(gè)例子

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="css" contenteditable="true" cid="n26" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body{
background-color: red
}
div{
widows:50px;
height:50px;
background-color:blue
}
</style>
</head>
<body>
<div> </div>
</body>
</html></pre>

image

可以看到主體的顏色是red, 其中一部分是blue

第二個(gè)例子

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="css" contenteditable="true" cid="n32" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body{
/background-color: red/
background-image: url("https://wx3.sinaimg.cn/mw690/719f9f6bly1g5p3mpvkxmj21w02ioqv5.jpg");
/圖片居中/
background-position: center;
/圖片不重復(fù)/
background-repeat: no-repeat;
}
/div{
widows:50px;
height:50px;
background-color:blue
}
/
</style>
</head>
<body>
<div> </div>
</body>
</html></pre>

image

可以寫成一句話

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="css" contenteditable="true" cid="n35" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"> background: url("https://wx3.sinaimg.cn/mw690/719f9f6bly1g5p3mpvkxmj21w02ioqv5.jpg") center no-repeat</pre>

背景屬性

屬性 描述
background 簡寫屬性,作用是將背景屬性設(shè)置在一個(gè)聲明中荆秦。
background-attachment 背景圖像是否固定或者隨著頁面的其余部分滾動(dòng)篱竭。
background-color 設(shè)置元素的背景顏色。
background-image 把圖像設(shè)置為背景步绸。
background-position 設(shè)置背景圖像的起始位置室抽。
background-repeat 設(shè)置背景圖像是否及如何重復(fù)。
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末靡努,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子晓折,更是在濱河造成了極大的恐慌惑朦,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,490評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件漓概,死亡現(xiàn)場離奇詭異漾月,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)胃珍,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,581評論 3 395
  • 文/潘曉璐 我一進(jìn)店門梁肿,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人觅彰,你說我怎么就攤上這事吩蔑。” “怎么了填抬?”我有些...
    開封第一講書人閱讀 165,830評論 0 356
  • 文/不壞的土叔 我叫張陵蓝牲,是天一觀的道長成肘。 經(jīng)常有香客問我淮逻,道長授账,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,957評論 1 295
  • 正文 為了忘掉前任签则,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘性置。我一直安慰自己,他們只是感情好揍堰,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,974評論 6 393
  • 文/花漫 我一把揭開白布鹏浅。 她就那樣靜靜地躺著,像睡著了一般个榕。 火紅的嫁衣襯著肌膚如雪篡石。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,754評論 1 307
  • 那天西采,我揣著相機(jī)與錄音凰萨,去河邊找鬼。 笑死械馆,一個(gè)胖子當(dāng)著我的面吹牛胖眷,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播霹崎,決...
    沈念sama閱讀 40,464評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼珊搀,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了尾菇?” 一聲冷哼從身側(cè)響起境析,我...
    開封第一講書人閱讀 39,357評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎派诬,沒想到半個(gè)月后劳淆,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,847評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡默赂,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,995評論 3 338
  • 正文 我和宋清朗相戀三年沛鸵,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片缆八。...
    茶點(diǎn)故事閱讀 40,137評論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡曲掰,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出奈辰,到底是詐尸還是另有隱情栏妖,我是刑警寧澤,帶...
    沈念sama閱讀 35,819評論 5 346
  • 正文 年R本政府宣布冯挎,位于F島的核電站底哥,受9級特大地震影響咙鞍,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜趾徽,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,482評論 3 331
  • 文/蒙蒙 一续滋、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧孵奶,春花似錦疲酌、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,023評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至载绿,卻和暖如春粥诫,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背崭庸。 一陣腳步聲響...
    開封第一講書人閱讀 33,149評論 1 272
  • 我被黑心中介騙來泰國打工怀浆, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人怕享。 一個(gè)月前我還...
    沈念sama閱讀 48,409評論 3 373
  • 正文 我出身青樓执赡,卻偏偏與公主長得像,于是被迫代替她去往敵國和親函筋。 傳聞我的和親對象是個(gè)殘疾皇子沙合,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,086評論 2 355

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