如何使用Bootstrap制作一个div容器,使其背景图像适合访问者的显示屏? 图像具有固定的高度和宽度。 如果屏幕较小,则应调整大小以避免x,y溢出。
如何使用Bootstrap制作一个div容器,使其背景图像适合访问者的显示屏? 图像具有固定的高度和宽度。 如果屏幕较小,则应调整大小以避免x,y溢出。
您可以这样使用 background-size
:
div.someclass {
background-size: cover;
}
这里有一篇很好的文章来自@Chris Coyier,展示了几种技巧:http://css-tricks.com/perfect-full-page-background-image/
首先,关于背景图片:
div.someclass{
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;
}
div.someclass{
margin-top:5%;
}
body
{
background: url(https://www.google.hu/images/srpr/logo4w.png);
background-size: cover;
}
body
{
background: url(https://www.google.hu/images/srpr/logo4w.png) no-repeat center center fixed;
background-size: cover;
}
这个对我有用:
body{
background-image: url('../url') ;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
height:100%;
}