我有一个网站(g-floors.eu),我想使背景(在css中,我已经为内容定义了bg-image)也响应。不幸的是,我真的不知道如何做到这一点,除了我能想到的一件事,但这是一个相当好的变通办法。创建多个图像,然后使用css屏幕大小来改变图像,但我想知道是否有更实用的方法来实现这一点。
基本上我想要实现的是图像(水印'G')自动调整大小,而不显示更少的图像。当然,如果可能的话
链接:g-floors.eu
到目前为止的代码(内容部分)
#content {
background-image: url('../images/bg.png');
background-repeat: no-repeat;
position: relative;
width: 85%;
height: 610px;
margin-left: auto;
margin-right: auto;
}
响应网站添加填充到底部图像高度/宽度x 100 = padding-bottom %:
http://www.outsidethebracket.com/responsive-web-design-fluid-background-images/
更复杂的方法:
http://voormedia.com/blog/2012/11/responsive-background-images-with-fixed-or-fluid-aspect-ratios
尝试调整背景大小eq Firefox Ctrl + M看到神奇的脚本,我认为最好的一个:
http://www.minimit.com/demos/fullscreen-backgrounds-with-centered-content
这里是sass mixin响应背景图像,我使用。它适用于任何块元素。当然,同样可以在纯CSS中工作,你只需要手动计算填充。
@mixin responsive-bg-image($image-width, $image-height) {
background-size: 100%;
height: 0;
padding-bottom: percentage($image-height / $image-width);
display: block;
}
.my-element {
background: url("images/my-image.png") no-repeat;
// substitute for your image dimensions
@include responsive-bg-image(204, 81);
}
比如http://jsfiddle.net/XbEdW/1/