在CSS中,我們可以使用background-image
屬性為文本框添加圖片,以下是一個(gè)簡(jiǎn)單的示例:
<div class="image-text-box"> 這是一段文本 </div>
.image-text-box { width: 200px; height: 100px; border: 1px solid #000; background-image: url('image.jpg'); background-repeat: no-repeat; background-position: center; }
在這個(gè)示例中,我們創(chuàng)建了一個(gè)帶有背景圖片的div
元素。background-image
屬性用于指定背景圖片,url('image.jpg')
表示圖片的位置。background-repeat: no-repeat;
表示圖片不會(huì)重復(fù),background-position: center;
表示圖片在背景中居中顯示。
你可以根據(jù)需要調(diào)整width
、height
、border
等屬性,以及圖片的URL和重復(fù)方式等背景屬性,來(lái)實(shí)現(xiàn)不同的效果。