1. 程式人生 > 實用技巧 >css怎麼設定圖片平鋪方式?

css怎麼設定圖片平鋪方式?

background-repeat屬性是用來設定背景影象如何平鋪的。預設地,背景影象在水平和垂直方向上重複。

屬性值:

  • repeat:即預設方式,完全平鋪背景;

  • no-repeat:在X及Y軸方向均不平鋪;

  • repeat-x:橫向平鋪背景;

  • repeat-y:縱向平鋪背景。

提示:背景影象的位置是根據 background-position 屬性設定的。如果未規定 background-position 屬性,影象會被放置在元素的左上角。

css背景圖片平鋪之完全平鋪背景的程式碼:

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div{
margin: 20px;
}
.content1 {
border: 1px solid #000fff;
height: 200px;
background-image: url(../2018.12.15/2.jpg);
background-repeat: repeat;
}
.content2 {
border: 1px solid #000fff;
height: 200px;
background-image: url(../2018.12.15/2.jpg);
background-repeat: repeat-x;
}
.content3 {
border: 1px solid #000fff;
height: 200px;
background-image: url(../2018.12.15/2.jpg);
background-repeat: repeat-y;
}
.content4 {
border: 1px solid #000fff;
height: 200px;
background-image: url(../2018.12.15/2.jpg);
background-repeat: no-repeat;
}
</style>
<div
class="content1"></div>
<div class="content2"></div>
<div class="content3"></div>
<div class="content4"></div>
</body>

</html>

廣州vi設計公司 http://www.maiqicn.com 我的007辦公資源網 https://www.wode007.com