国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > CSS > 正文

HTML與CSS中背景相關(guān)屬性

2020-03-24 17:10:36
字體:
供稿:網(wǎng)友
這次給大家?guī)鞨TML與CSS中背景相關(guān)屬性,使用HTML與CSS中背景相關(guān)屬性的注意事項(xiàng)有哪些,下面就是實(shí)戰(zhàn)案例,一起來看一下。

一. 背景尺寸屬性

1.什么是背景尺寸屬性
背景尺寸屬性是CSS3中新增的一個(gè)屬性, 專門用于設(shè)置背景圖片大小

background-size:xxxx;

取值:

1.具體像素 background-size:200px 100px;2.百分比 background-size:100% 80%;3.寬度等比拉伸 background-size:auto 100px;4.高度等比拉伸 background-size:100px auto;5.cover background-size:cover;

5.1告訴系統(tǒng)圖片需要等比拉伸

5.2告訴系統(tǒng)圖片需要拉伸到寬度 a 和 /a 高度都填滿元素

6. contain background-size:contain;

6.1告訴系統(tǒng)圖片需要等比拉伸

6.2告訴系統(tǒng)圖片需要拉伸到寬度 a 或 /a 高度都填滿元素( a 只保證一邊填滿 /a )

background-size

二. 背景圖片定位區(qū)域?qū)傩?/p>

a background-origin /a : 告訴系統(tǒng)背景圖片從什么區(qū)域開始顯示,默認(rèn)情況下就是從padding區(qū)域開始顯示;

取值:

1. a padding-box /a :默認(rèn)值 background-origin: padding-box; 告訴系統(tǒng)背景圖片從什么區(qū)域開始顯示,默認(rèn)情況下就是從padding區(qū)域開始顯示; 2. a border-box /a background-origin:border-box; 從border位置開始 3. a content-box /a background-origin:content-box;從content位置開始
 html lang= en head meta charset= UTF-8 title 113-背景圖片定位區(qū)域?qū)傩?/title style *{ margin: 0; padding: 0; } ul li{ list-style: none; float: left; width: 100px; height: 100px; text-align: center; line-height: 100px; border: 20px dashed #000; padding: 50px; margin-left: 20px; background: url( images/dog.jpg ) no-repeat; } ul li:nth-child(2){ /* 告訴系統(tǒng)背景圖片從什么區(qū)域開始顯示, 默認(rèn)情況下就是從padding區(qū)域開始顯示 */ background-origin: padding-box; } ul li:nth-child(3){ background-origin:border-box; } ul li:nth-child(4){ background-origin:content-box; } /style /head body ul li 默認(rèn) /li li padding /li li border /li li content /li /ul /body /html 

背景圖片定位區(qū)域?qū)傩?br>

三. 背景繪制區(qū)域?qū)傩?/p>

 a background-clip:xxx; /a 背景繪制區(qū)域?qū)傩允菍iT用于指定從哪個(gè)區(qū)域開始繪制背景的, 默認(rèn)情況下會(huì)從border區(qū)域開始繪制背景 html lang= en head meta charset= UTF-8 title 114-背景繪制區(qū)域?qū)傩?/title style *{ margin: 0; padding: 0; } ul li{ list-style: none; float: left; width: 100px; height: 100px; text-align: center; line-height: 100px; border: 20px dashed #000; padding: 50px; margin-left: 20px; background: red url( images/dog.jpg ) no-repeat; } ul li:nth-child(2){ /* 背景繪制區(qū)域?qū)傩允菍iT用于指定從哪個(gè)區(qū)域開始繪制背景的, 默認(rèn)情況下會(huì)從border區(qū)域開始繪制背景 */ background-clip: padding-box; } ul li:nth-child(3){ background-clip: border-box; } ul li:nth-child(4){ background-clip: content-box; } /style /head body ul li 默認(rèn) /li li padding /li li border /li li content /li /ul /body /html 

背景繪制區(qū)域?qū)傩?紅色為繪制區(qū)域)

四. 多重背景圖片

a 先添加的背景圖片會(huì)蓋住后添加的背景圖片 /a

元素c3之后可以設(shè)置多張背景圖片
多張背景圖片之間用逗號(hào)隔開即可

background: url( images/animal1.png ) no-repeat left top,url( images/animal2.png ) no-repeat right top,url( images/animal3.png ) no-repeat left bottom;

注意點(diǎn):

先添加的背景圖片會(huì)蓋住后添加的背景圖片

background: url( images/animal1.png ) no-repeat left top,url( images/animal2.png ) no-repeat right top,url( images/animal3.png ) no-repeat left bottom,url( images/animal4.png ) no-repeat right bottom,url( images/animal5.png ) no-repeat center center;

建議在編寫多重背景時(shí)拆開編寫

background-image: url( images/animal1.png ),url( images/animal2.png ),url( images/animal3.png background-repeat: no-repeat, no-repeat, no-repeat; background-position: left top, right top, left bottom;

完整代碼如下:

 html lang= en head meta charset= UTF-8 title 115-多重背景圖片 /title style *{ margin: 0; padding: 0; } p{ width: 500px; height: 500px; border: 1px solid #000; margin: 0 auto; /* 多張背景圖片之間用逗號(hào)隔開即可 注意點(diǎn): 先添加的背景圖片會(huì)蓋住后添加的背景圖片 建議在編寫多重背景時(shí)拆開編寫 */ /*background: url( images/animal1.png ) no-repeat left top,url( images/animal2.png ) no-repeat right top,url( images/animal3.png ) no-repeat left bottom,url( images/animal4.png ) no-repeat right bottom,url( images/animal5.png ) no-repeat center center;*/ background-image: url( images/animal1.png ),url( images/animal2.png ),url( images/animal3.png background-repeat: no-repeat, no-repeat, no-repeat; background-position: left top, right top, left bottom; } /style /head body p /p /body /html 


多重背景圖片

四.多重背景圖片聯(lián)系

 a 先添加的背景圖片會(huì)蓋住后添加的背景圖片 /a  html lang= en head meta charset= UTF-8 title 116-多重背景圖片-練習(xí) /title style *{ margin: 0; padding: 0; } p{ width: 600px; height: 190px; border: 1px solid #000; margin: 100px auto; background-image: url( images/bg-plane.png ),url( images/bg-sun.png ), url(images/bg-clouds.png); background-repeat: no-repeat, no-repeat, no-repeat; background-size: 50px 50px, 50px 50px, auto auto; background-position: 50px 150px, 400px 50px, 0px 0px; animation: move 10s linear 0s infinite normal; } @keyframes move { from{ background-position: 50px 150px, 400px 50px, 0px 0px; } to{ background-position: 500px -150px, 400px 50px, -600px 0px; } } /style /head body p /p /body /html 

相信看了本文案例你已經(jīng)掌握了方法,更多精彩請(qǐng)關(guān)注php 其它相關(guān)文章!

推薦閱讀:

HTML與CSS中2D轉(zhuǎn)換模塊

HTML與CSS中的過渡模塊

H5中的定位

以上就是HTML與CSS中背景相關(guān)屬性的詳細(xì)內(nèi)容,html教程

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 和政县| 章丘市| 青阳县| 繁昌县| 扶余县| 化德县| 鹤山市| 蕉岭县| 革吉县| 凤城市| 香河县| 邮箱| 射洪县| 阿拉善右旗| 巢湖市| 阿鲁科尔沁旗| 永兴县| 乌鲁木齐市| 儋州市| 关岭| 曲沃县| 武汉市| 阿合奇县| 庄河市| 辛集市| 浪卡子县| 汶川县| 田阳县| 鄄城县| 芦溪县| 怀远县| 延安市| 靖安县| 太和县| 新巴尔虎左旗| 玉门市| 兰州市| 山丹县| 微博| 平武县| 连城县|