css 如何使大图只显示中间部分

将图片设置成背景图

<div style="width: 100%;height: 400px;">
        <div style=" 
        width: 100%;
        height: 400px;
    background:url(img/banner.jpg) no-repeat 50%;background-size:200% 100%"></div>
</div>

 

注意,第一个大盒子可以不设置宽和高,由内容(即第二个大盒子)撑开,但是第二个盒子必须设置高

posted @ 2021-01-17 09:21  迷路的搬砖人  阅读(464)  评论(0)    收藏  举报