61,115
社区成员
发帖
与我相关
我的任务
分享
<style>
#tt {
background-color:#FF0000;
width: 100%;
height:500px;
overflow: hidden;
}
#tt .img
{
width:1920px;
margin:0 calc(50% - 960px);
}
</style>
<div id="tt"><img src="http://b.zol-img.com.cn/desk/bizhi/image/5/1920x1080/1418984437613.jpg" class="img"/></div>
#tt {
background-color:#FF0000;
margin: auto;
width: 100%;
height:400px;
overflow: hidden; /* 添加的 */
}
正常情况下是这样的需求,在宽度上适应屏幕,不出现水平方向上的滚动条,高度随着宽度等比例变化,即图片宽高成比例变化,可以这么做:
#tt .img {
width: 100%;
}