主要思路:图片100%显示,然后用外面的容器对图片进行遮挡。(PS:下面的做法都会对图片进行裁剪)

1.布局:div + img元素;

兼容性好,但是图片要设置个相对比较大的值,图片本身两边留白,内容处于中间,适用于banner;

        .img-wrap {
            position: relative;
            min-width: 1000px;
            width: 100%;
            max-width: 2000px;
            height: 500px;
            overflow: hidden;
        }

        .img-wrap img {
            width: 2000px;
            position: absolute;
            left: 50%;
            margin-left: -1000px;
        }
    


2.布局:div + background-image属性(background-size,object-fit用其中一个属性即可);

布局简单,但是对于ie的兼容性不好,特别是object-fit对所有ie都不兼容(查看兼容时间:2018-10-14);

        .bg-wrap{
            min-width: 1000px;
            width: 100%;
            max-width: 2000px;
            height: 500px;
            overflow: hidden;
            background:url(demo.jpg) no-repeat center;
            background-size:cover;
            /* object-fit: cover; */
        }