简体   繁体   English

缩小图像,宽度100%,固定高度

[英]scale image down, width 100% and fixed height

I have high resolution images (2592x1944) and I'm having problem to show them in a slider. 我有高分辨率的图像(2592x1944),但无法在滑块中显示它们。

I'm using a fixed container (width 100% and height 550px) and inside it the image as background (maybe I should use img tag?). 我使用的是固定容器(宽度为100%,高度为550px),并且在其中将图片作为背景(也许我应该使用img标签?)。

<div class="header-right">
    <div class="banner">
         <div class="slider">
            <div class="callbacks_container">
                <ul class="rslides" id="slider">
                    <li>
                        <div class="banner">
                            <div class="caption">
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>

And the CSS (the background url is in the html so i can dynamically add more slides with php): 和CSS(背景url在html中,因此我可以用php动态添加更多幻灯片):

.slider {
    position: relative;
}
.rslides {
    position: relative;
    list-style: none;
    overflow: hidden;
    width: 100%;
    padding: 0;
    margin: 0;
}
.rslides li {
    -webkit-backface-visibility: hidden;
    position: absolute;
    display: none;
    width: 100%;
    left: 0;
    top: 0;
}
.rslides li:first-child {
    position: relative;
    float: left;
    width: 100%;
    height: 550px;
}
.banner{
    background-repeat: no-repeat;
    background-size: contain;
    -webkit-background-size: contain;
    -moz-background-size: contain;
    -o-background-size: contain;
}

Currently it's displaying the full image scaled (height 550px) aligned to left. 目前,它正在显示按比例缩放(高度550像素)的完整图像,并向左对齐。

I'd like to show the image with a full width and the borders cropped (in a way that the image can fit in the 100% of the screen and have a good amount of the height and can be properly displyed). 我想显示全角图像并剪裁边框(以这种方式图像可以适合屏幕的100%并具有足够的高度并可以正确显示)。 The images are camera photos (smartphone) and they have too much height to be in a 16:9 format so maybe cropping it it'll help. 这些图像是相机照片(智能手机),并且它们的高度过高,无法以16:9格式显示,因此可能会对其进行裁剪会有所帮助。 I think it's better to use css rather than modify the images one by one. 我认为使用CSS而不是一张一张地修改图像更好。

How can I do this? 我怎样才能做到这一点?

http://jsfiddle.net/5n9mo3od/ http://jsfiddle.net/5n9mo3od/

Did you tried to use cover instead of contain for this? 您是否尝试过使用封面而不是包含内容? Cropping is in fact a good solution because not the whole image would be loaded. 裁剪实际上是一个很好的解决方案,因为不会加载整个图像。 An image of 2500+ width can be hard to load on a smartphone. 宽度超过2500的图像可能难以加载到智能手机上。

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

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