zoukankan      html  css  js  c++  java
  • 网页背景图片Full Page Background Image

    The goal here is a background image on a website that covers the entire browser window at all times. Let's put some specifics on it:

    • Fills entire page with image, no white space
    • Scales image as needed
    • Retains image proportions (aspect ratio)
    • Image is centered on page
    • Does not cause scrollbars
    • As cross-browser compatible as possible
    • Isn't some fancy shenanigans like Flash

    Awesome, Easy, Progressive CSS3 Way

    We can do this purely through CSS thanks to the background-size property now in CSS3. We'll use the html element (better than body as it's always at least the height of the browser window). We set a fixed and centered background on it, then adjust it's size using background-size set to the cover keyword.

    html { 
      background: url(images/bg.jpg) no-repeat center center fixed; 
      -webkit-background-size: cover;
      -moz-background-size: cover;
      -o-background-size: cover;
      background-size: cover;
    }

    在chrome中好像不加background-size:也可以。

    另外的几种方法,参见:

    http://css-tricks.com/perfect-full-page-background-image/

  • 相关阅读:
    wikiquote
    zz 勵志貼,成功是努力加对的方向
    # 电纸书
    # 崔寶秋
    好的程序員
    深度学习引擎
    再见乱码:5分钟读懂MySQL字符集设置
    Linux基础:用tcpdump抓包
    Linux基础:文件查找find
    Linux基础:xargs命令
  • 原文地址:https://www.cnblogs.com/youxin/p/3029688.html
Copyright © 2011-2022 走看看