大图片随浏览器水平居中显示

css样式:

<style>
*{margin: 0; }
.ads-detail {
1000px;
/*height: 1000px;*/
position: relative;
margin: 0 auto;
}
.ads-detail p{
position: absolute;
1920px;
left:-465px;
top:0px;
}

.ads-detail img {
display: block;
100%;
}
</style>

js代码:
<script>
window.onload = function(){
//设置ads_detail高度
var arrP = document.getElementById("ads-detail").getElementsByTagName("p");
var adsHeight = 0;
for(var i = 0 ; i < arrP.length; i++){
adsHeight += arrP[i].clientHeight || arrP[i].offsetHeight;
}
document.getElementById("ads-detail").style.height = adsHeight  + "px";
};
</script>

html结构:
<div style=" 100%; overflow: hidden;">
<div class="ads-detail" id="ads-detail">
<p>
<img src="0e7422be-e329-4eb9-a1a3-f85491c18d14.jpg">
</p>
</div>
</div>

原文地址:https://www.cnblogs.com/mengwei-ziyun/p/5355176.html