背景图像重新调整大小

时间:2016-02-21 05:15:34

标签: html css twitter-bootstrap-3 background-image image-resizing

添加背景图像后,还有一个空白区域。 当bg-size更改为'cover'而重新调整为小分辨率时,会留下空白区域,请检查自己 codepen

body {
  margin:0;
  background-image:url('http://www.fg-a.com/wallpapers/yellow-flowers-green.jpg');
  background-repeat: no-repeat;
  background-size:auto;
}

1 个答案:

答案 0 :(得分:0)

你对background-size:cover;做了正确但是......
你错过了background-position财产。

最简单的方法是:

html, body{
    height:100%; /* Don't forget to set html and body to height 100%! */
}
body {
    margin: 0;
    background: url('green.jpg') 50%; /* where 50% is our background-position (center) */
    background-size: cover;
}

这真的是你所需要的 http://jsbin.com/bogacad/1/edit?html,css,output

https://developer.mozilla.org/en-US/docs/Web/CSS/background-position