在CSS中放置多張圖片,可以通過使用CSS的background-image
屬性來實現(xiàn),這個屬性允許你在一個元素中設置多個圖片作為背景,下面是一些示例代碼,展示如何在CSS中放置多張圖片:
示例1: 使用逗號分隔的圖片列表
div { background-image: url(image1.png), url(image2.png), url(image3.png); background-position: left, center, right; background-repeat: no-repeat, repeat, no-repeat; }
示例2: 使用CSS的@image
規(guī)則
@image image1 = url(image1.png); @image image2 = url(image2.png); @image image3 = url(image3.png); div { background-image: image1, image2, image3; background-position: left, center, right; background-repeat: no-repeat, repeat, no-repeat; }
示例3: 使用CSS的image()
函數(shù)
div { background-image: image(url(image1.png)), image(url(image2.png)), image(url(image3.png)); background-position: left, center, right; background-repeat: no-repeat, repeat, no-repeat; }
示例4: 使用CSS的url()
函數(shù)和linear-gradient()
函數(shù)結(jié)合使用
div { background-image: linear-gradient(to right, url(image1.png) 50%, url(image2.png) 50%), url(image3.png); background-position: left, right; background-repeat: no-repeat, no-repeat; }
示例5: 使用CSS的grid
布局和repeat()
函數(shù)放置圖片
div { display: grid; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr; grid-gap: 10px; background-image: url(image1.png), url(image2.png), url(image3.png); background-position: left, center, right; background-repeat: no-repeat, no-repeat, no-repeat; }
示例6: 使用CSS的flex
布局和repeat()
函數(shù)放置圖片
div { display: flex; justify-content: space-between; align-items: center; background-image: url(image1.png), url(image2.png), url(image3.png); background-position: left, right; background-repeat: no-repeat, no-repeat; }
版權(quán)聲明:除非特別標注,否則均為本站原創(chuàng)文章,轉(zhuǎn)載時請以鏈接形式注明文章出處。