简体   繁体   English

响应式横幅图片

[英]Responsive banner image

I am developing a responsive website which has a large banner image which spans edge to edge. 我正在开发一个响应式网站,该网站的横幅广告幅面很大。 The problem is that its supposed to be a static height regardless of the screen size. 问题在于,无论屏幕大小如何,它都应该是静态高度。 So when I set the image to width:100% it looks great in full size, but as soon as I start to shrink the screen the image gets shorter then the width that it needs to be. 因此,当我将图像设置为width:100%时,它在全尺寸下看起来不错,但是一旦我开始缩小屏幕,图像就会变短,然后就需要它的宽度。 How can I set this up so that the image height appears to never change and when the screen size is smaller then the image size it zooms in and crops the edges? 我该如何进行设置,以使图像高度看起来永远不会改变,并且当屏幕尺寸较小时,图像尺寸会放大并裁切边缘?

http://bit.ly/1qxmZir http://bit.ly/1qxmZir

HTML HTML

<div id="hd-img">
    <img src="http://72.52.242.20/~camacoll/wp-content/uploads/2014/05/inner-hd.jpg"> 
</div>

CSS CSS

#hd-img {
    max-height: 352px;
}

img {
    width: 100%;
    height: auto;
    left: 100%;
    margin-left: -200%;
    position: relative;
} 

One way you could do it is like this . 你可以做到这一点的方法之一是喜欢这样

/* CSS */

#hd-img {
    height: auto;
    overflow: hidden;
}

#hd-img img {
    /* Optional max width: 600px; */
    display: block;
    margin: 0 auto;
}

尝试这个:

background-image:url(../images/header-bannerbg.png);background-position:fixed;background-repeat:no-repeat;height:580px;-webkit-background-size: 100% 100%;-moz-background-size: 100% 100%;-o-background-size: 100% 100%;background-size: 100% 100%;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM