
- CSS 教程
- CSS - 首頁
- CSS - 路線圖
- CSS - 簡介
- CSS - 語法
- CSS - 選擇器
- CSS - 引入
- CSS - 測量單位
- CSS - 顏色
- CSS - 背景
- CSS - 字型
- CSS - 文字
- CSS - 圖片
- CSS - 連結
- CSS - 表格
- CSS - 邊框
- CSS - 塊級邊框
- CSS - 內聯邊框
- CSS - 外邊距
- CSS - 列表
- CSS - 內邊距
- CSS - 游標
- CSS - 輪廓
- CSS - 尺寸
- CSS - 捲軸
- CSS - 內聯塊
- CSS - 下拉選單
- CSS - 可見性
- CSS - 溢位
- CSS - 清除浮動
- CSS - 浮動
- CSS - 箭頭
- CSS - 調整大小
- CSS - 引號
- CSS - 順序
- CSS - 定位
- CSS - 連字元
- CSS - 懸停
- CSS - 顯示
- CSS - 聚焦
- CSS - 縮放
- CSS - 轉換
- CSS - 高度
- CSS - 連字元字元
- CSS - 寬度
- CSS - 不透明度
- CSS - Z-Index
- CSS - 底部
- CSS - 導航欄
- CSS - 覆蓋層
- CSS - 表單
- CSS - 對齊
- CSS - 圖示
- CSS - 圖片庫
- CSS - 註釋
- CSS - 載入器
- CSS - 屬性選擇器
- CSS - 組合器
- CSS - 根元素
- CSS - 盒模型
- CSS - 計數器
- CSS - 剪裁
- CSS - 書寫模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - 指標事件
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS 高階
- CSS - 網格
- CSS - 網格佈局
- CSS - Flexbox
- CSS - 可見性
- CSS - 定位
- CSS - 層
- CSS - 偽類
- CSS - 偽元素
- CSS - @規則
- CSS - 文字效果
- CSS - 分頁媒體
- CSS - 列印
- CSS - 佈局
- CSS - 驗證
- CSS - 圖片精靈
- CSS - Important
- CSS - 資料型別
- CSS3 教程
- CSS3 - 教程
- CSS - 圓角
- CSS - 邊框圖片
- CSS - 多背景
- CSS - 顏色
- CSS - 漸變
- CSS - 盒陰影
- CSS - 盒裝飾中斷
- CSS - Caret Color
- CSS - 文字陰影
- CSS - 文字
- CSS - 2D 變換
- CSS - 3D 變換
- CSS - 過渡
- CSS - 動畫
- CSS - 多列
- CSS - 盒尺寸
- CSS - 工具提示
- CSS - 按鈕
- CSS - 分頁
- CSS - 變數
- CSS - 媒體查詢
- CSS - 函式
- CSS - 數學函式
- CSS - 遮罩
- CSS - 形狀
- CSS - 樣式圖片
- CSS - 特異性
- CSS - 自定義屬性
- CSS 響應式
- CSS RWD - 簡介
- CSS RWD - 視口
- CSS RWD - 網格檢視
- CSS RWD - 媒體查詢
- CSS RWD - 圖片
- CSS RWD - 影片
- CSS RWD - 框架
- CSS 工具
- CSS - PX 到 EM 轉換器
- CSS - 顏色選擇器和動畫
- CSS 資源
- CSS - 有用資源
- CSS - 討論
CSS - background-repeat 屬性
CSS background-repeat 屬性控制背景圖片的重複方式。圖片可以在水平和垂直方向上重複,也可以不重複。
語法
background-repeat: repeat | repeat-x | repeat-y | no-repeat | space | round | initial | inherit;
屬性值
值 | 描述 | |
---|---|---|
repeat | 背景圖片在水平和垂直方向上都重複。預設值。 | |
repeat-x | 背景圖片在水平方向上重複。 | |
repeat-y | 背景圖片在垂直方向上重複。 | |
no-repeat | 背景圖片不重複。 | |
space | 儘可能多地重複圖片,但不剪裁。第一個和最後一個圖片固定在元素的兩側,空白區域均勻分佈在圖片之間。 | |
round | 重複背景圖片並將其壓縮或拉伸以填充空白區域。 | |
initial | 將屬性設定為其初始值。 | |
inherit | 從父元素繼承該屬性。 |
CSS 背景重複屬性示例
下面介紹了使用不同值的 background-repeat 屬性的示例。
圖片重複
要使背景圖片在垂直和水平方向上都重複,我們使用 repeat 值。如下例所示。
示例
<!DOCTYPE html> <html> <head> <style> .repeat { background-image: url('/css/images/tutimg.png'); background-repeat: repeat; width: 800px; height: 400px; position: relative; } </style> </head> <body> <h2>CSS background-repeat property</h2> <div class="repeat"></div> </body> </html>
水平方向圖片重複
要使背景圖片在水平方向上重複,我們使用 repeat-x 值。如下例所示。
示例
<!DOCTYPE html> <html> <head> <style> .repeat-x { background-image: url('/css/images/tutimg.png'); background-repeat: repeat-x; width: 800px; height: 300px; position: relative; } </style> </head> <body> <h2>CSS background-repeat property</h2> <div class="repeat-x"></div> </body> </html>
垂直方向圖片重複
要使背景圖片在垂直方向上重複,我們使用 repeat-y 值。如下例所示。
示例
<!DOCTYPE html> <html> <head> <style> .repeat-y { background-image: url('/css/images/tutimg.png'); background-repeat: repeat-y; width: 800px; height: 300px; position: relative; } </style> </head> <body> <h2>CSS background-repeat property</h2> <div class="repeat-y"></div> </body> </html>
阻止圖片重複
要阻止背景圖片重複,我們使用 no-repeat 值。如下例所示。
示例
<!DOCTYPE html> <html> <head> <style> .no-repeat { background-image: url('/css/images/tutimg.png'); background-repeat: no-repeat; width: 800px; height: 300px; position: relative; } </style> </head> <body> <h2>CSS background-repeat property</h2> <div class="no-repeat"></div> </body> </html>
帶間距的圖片重複
要使圖片重複多次並在它們之間均勻分佈空白區域,我們使用 space 值。如下例所示。
示例
<!DOCTYPE html> <html> <head> <style> .space { background-image: url('/css/images/tutimg.png'); background-repeat: space; width: 800px; height: 300px; position: relative; } </style> </head> <body> <h2>CSS background-repeat property</h2> <div class="space"></div> </body> </html>
拉伸以填充空白區域
要使圖片重複多次並在它們之間留下少量空白區域,我們使用 round 值。如下例所示。
示例
<!DOCTYPE html> <html> <head> <style> .round { background-image: url('/css/images/tutimg.png'); background-repeat: round; width: 800px; height: 300px; position: relative; } </style> </head> <body> <h2>CSS background-repeat property</h2> <div class="round"></div> </body> </html>
支援的瀏覽器
屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
background-repeat | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
css_properties_reference.htm
廣告