萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> Div CSS 教學

CSS 實現大背景網頁自適應:圖片+背景色、雙層背景圖技巧

大螢幕下背景圖不夠寬/高導致邊緣露白,兩大經典技巧完美解決:

技巧一:圖片邊緣純色 + body 背景色同色

背景圖邊緣純色

body {
  margin: 0; padding: 0;
  background: #f8f7e5 url(wdw-bg.jpg) no-repeat center top;
  width: 100%; display: table; /* 修正舊 IE 高度塌陷 */
}

圖片邊緣為純色 #f8f7e5,超出圖片範圍自動顯示 body 背景色,無縫銜接。

技巧二:雙層背景圖(body 重複紋理 + wrapper 主視覺)

body 重複紋理

wrapper 主視覺

body {
  background: url(cork-pattern.gif) repeat; /* 輕量可平鋪紋理 */
}
#wrapper {
  background: url(main-visual.jpg) no-repeat center top;
  min-height: 100vh; /* 確保至少一屏高 */
}

關鍵:主視覺圖邊緣顏色與紋理主色調接近(稍深),視覺自然過渡。

現代最佳實踐:CSS3 多重背景

body {
  background:
    url(main-visual.jpg) no-repeat center top,
    url(cork-pattern.gif) repeat;
  background-color: #f8f7e5; /* 終極兜底色 */
}

單一元素、無額外 wrapper、支援所有現代瀏覽器(IE9+),為當前首選方案。

copyright © 萬盛學電腦網 all rights reserved