<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta id="robots" content="all" />
<meta name="Description" content="图片垂直居中 图片等比例缩放的方法" />
<meta name="Keywords" content="图片垂直居中" />
<meta id="author" content="土人老徐 http://K.css6.com" />
<meta id="Copyright" content="Copyright 2010-2011 K.css6.com. All Rights Reserved" />
<link href="http://style.china.alibaba.com/css/fdevlib/reset/reset.css" type="text/css" media="screen" rel="stylesheet" />
<title>分享图片垂直居中,图片等比例缩放的方法 </title>
<style type="text/css" media="screen" rel="stylesheet">
.img_list ul li{ float:left; margin:10px; width:202px; height:202px; overflow:hidden; display:inline;}
.img_list ul li a{ width:200px; height:200px; overflow:hidden; display:table-cell; *display:block; line-height:200px; font-size:200px; *font-size:175px; text-align:center;border:1px solid #f00; vertical-align:middle; font-family:Arial;}
.img_list ul li img { vertical-align:middle; vertical-align:middle;}
</style>
</head>
<body>
<div class="img_list">
<ul id="img_list">
<li>
<a href="#">
<img src="http://i00.c.aliimg.com/news/upload/5000780/2_1263433563767.jpg" alt="示例图片" />
</a>
</li>
<li>
<a href="#">
<img src="http://img.china.alibaba.com/news/upload/5000260/392192_1263174952956.jpg" alt="示例图片" />
</a>
</li>
<li>
<a href="#">
<img src="http://i00.c.aliimg.com/news/upload/profile/huodong/guanghuo/03/45_1263268910318.jpg" alt="示例图片" />
</a>
</li>
</ul>
</div>
<script type="text/javascript">
/*
* auto resize image
* @param img img obj
* @param w custom width
* @param h custom height
*/
resizeImage=function(img,w,h) {
img.removeAttribute('width');
img.removeAttribute('height');
var pic;
if(document.all) {
var pic=new Image();
pic.src=img.src;
} else pic=img;
//check images exist and width&height >0 and custom width >0
if(pic&&pic.width&&pic.height&&w) {
if(!h) h=w;
if(pic.width>w||pic.height>h) {
var scale=pic.width/pic.height,fit=scale>=w/h;
if(document.all) img=img.style;
img[fit?'width':'height']=fit?w:h;
if(document.all) img[fit?'height':'width']=(fit?w:h)*(fit?1/scale:scale);
}
}
};
window.onload=function(){
var images=document.getElementById('img_list').getElementsByTagName('img');
for(var i=0;i<images.length;i++){
resizeImage(images[i],200);
}
};
</script>
</body>
</html>
如果你觉得本文介绍的图片垂直居中方法值得收藏,请附上本文的网址,谢谢。
本文出处:http://k.css6.com/?p=41
分享到:
相关推荐
jquery图片等比例缩放图片左右垂直居中 jquery图片等比例缩放图片左右垂直居中
NULL 博文链接:https://vipshow.iteye.com/blog/1848912
图片水平垂直居中 用很精简的代码,实现图片水平垂直居中 效果
css图片垂直居中方法
1、定制Datawindow GRID模式的外观,包括线条、文本垂直居中、背景颜色和背景图片、选择块颜色、当前行颜色、合并表头、编辑框按钮等 2、提供了窗口自动控件缩放布局功能 3、改进了打开和保存对话框
DIV+CSS 图片垂直居中效果
在前端开发中,有时候在展示很多图片的时候,由于图片的长宽不一致,需要将图片按照左右垂直居中的方式来显示,改插件实例就是按照这种方式来实现的。
图片水平垂直居中 好用 图片水平垂直居中 图片水平垂直居中 图片水平垂直居中
js实现图片等比例缩放 我将网络上流传的,改成了横向居中和纵向居中,非常实用。
写网页中的图片垂直居中的代码。例子教你怎么快速的方便的写垂直居中
图片等比例缩放个人最优化版(IE6,IE7,FF)
用CSS来实现img图片在DIV层中上下左右都居中,并且图片等比例缩放。很实用的
div框水平垂直居中跟内容垂直居中
垂直居中代码、垂直居中样式,图片垂直居中代码参考。
任意图片在div里的垂直居中!
在DIV中图片垂直/水平居中(最简单方法)
position: absolute,display:table-cell,display:flex四种垂直居中的方法
继承系统的TextBox,支持文字垂直居中;自动折行(即WordWrap = True)也支持垂直居中。
这是几种图片在div层的居中方法,其中垂直居中不好实现的问题是兼容性问题,其中有兼容性不错的居中方法实例。