上一篇文章中我們了解了定位元素背景圖像的方法,請(qǐng)看《一招搞定css定位元素的背景圖像》。這次我們來(lái)了解一下設(shè)置背景圖重復(fù)的方法,有需要的可以參考參考。
當(dāng)我們有一張背景圖的時(shí)候,如何設(shè)置這個(gè)背景圖的平鋪方式呢?
先來(lái)看一個(gè)小栗子,就拿上篇文章的代碼吧。
<style> div{ background-image: url("images/3.jpg"); background-repeat:no-repeat; background-position:left; } </style> </head> <body><div> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> <p>為了顯示,表明這個(gè)一個(gè)p元素</p><p><span>立即學(xué)習(xí)</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免費(fèi)學(xué)習(xí)筆記(深入)</a>”;</p> </div> </body>
這個(gè)結(jié)果是
我們可以看到,這個(gè)小例子中的背景圖一直都是這張,但是圖片出現(xiàn)的次數(shù)發(fā)生了改變,這是什么原因呢?可以看到,我們修改了background-repeat這個(gè)屬性的值,今天我們就來(lái)說(shuō)一下這個(gè)屬性。
background-repeat屬性設(shè)置是否及如何重復(fù)背景圖像。背景圖像可以沿著水平軸,垂直軸,兩個(gè)軸重復(fù),或者根本不重復(fù)。默認(rèn)地,背景圖像在水平和垂直方向上重復(fù)。重復(fù)的圖像被剪裁為元素的大小,但它們可以縮放 (使用round) 或者均勻地分布?(使用space)。
該屬性從原圖像開(kāi)始重復(fù),原圖像由background-image定義,并根據(jù)background-position的值放置。
在這個(gè)屬性中一共有四個(gè)屬性值,分別是repeat,repeat-x,repeat-y和no-repeat。其中,repeat代表背景圖像將在垂直方向和水平方向重復(fù);repeat-x代表背景圖像將在水平方向重復(fù);repeat-y代表背景圖像將在垂直方向重復(fù);no-repeat代表背景圖像不重復(fù),只出現(xiàn)一次。
推薦學(xué)習(xí):css視頻教程
以上就是如何使用css設(shè)置背景圖的重復(fù)與否的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注php中文網(wǎng)其它相關(guān)文章!
每個(gè)人都需要一臺(tái)速度更快、更穩(wěn)定的 PC。隨著時(shí)間的推移,垃圾文件、舊注冊(cè)表數(shù)據(jù)和不必要的后臺(tái)進(jìn)程會(huì)占用資源并降低性能。幸運(yùn)的是,許多工具可以讓 Windows 保持平穩(wěn)運(yùn)行。
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://www.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)