css 图片内容在不同分辨率下居中显示(演示的图片宽度是1920px,当图片宽度大于显示屏的宽度时)...

1.img 图片内容在不同分辨率下居中显示(如果隐藏多余,在img外面套一个div  设定overflow: hidden。div的大小就是img显示区域的大小)

 <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
body,div,p,a,img,ul,ol,li{
    margin: 0;
    padding: 0;
}
#tab { overflow:hidden; 
    width
:100%;要显示的宽度 } #tab img{ overflow:hidden; width:1920px; height:447px; position: relative;
   left:50%; 刚好在中间
   margin-left:-960px;图片宽度一半 } #tab>img:not(:first-child){ display:none; } </style> <script> //js幻灯片 window.onload = function(){ var images = document.getElementsByTagName('img'); var pos = 0; var len = images.length; setInterval(function(){ images[pos].style.display = 'none'; pos = ++pos == len ? 0 : pos; images[pos].style.display = 'inline'; },3000); }; </script> </head> <body> <div id="tab"> <img src="images/20160907_100403_003.jpg" width="1920px" height="447"/> <img src="images/20160907_100403_004.jpg" width="1920px" height="447"/> </div> </body> </html>

2.背景 图片内容在不同分辨率下居中显示(演示的图片宽度是1920px,当图片宽度大于显示屏的宽度时)

<div class="index-panel-pic1"></div>
.index-panel-pic1{
    background: url(../images/20160907_100403_000.gif) no-repeat center center;
    width:100%;
    height:650px;
    background-size: cover;
}

 

转载于:https://www.cnblogs.com/wishjm/p/5850239.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值