推荐.NET教程: ASP.NET C# 开发环境 Ajax教程 控件开发 统计报表 数据库 Web服务 安装部署 CommunityServer NHibernate DataGrid/GridView 实用代码 VS2005
示例源码 MVC/三层 SqlHelper 入门源码 开源 CMS Ajax/Atlas C#.net 毕业设计 源码 经典代码 商业 本站作品 持久层 随书源码 WebService 英文/汉化 Asp.net2.0

阿牛·乐园

每天进步一点点

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  80 随笔 :: 14 文章 :: 389 评论 :: 13 引用

2007年3月22日 #

<!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" />
<title>一个div里面图片垂直居中的例子</title>
<style type="text/css">
<!--
div 
{
width
:120px;
height
:100px;
border
:1px solid #ccc;
overflow
:hidden;
position
:relative;
display
:table-cell;
text-align
:center;
vertical-align
:middle;
background-color
:blue;
}

div span 
{
position
:static;
+position
:absolute;
top
:50%;
}

img 
{
position
:static;
+position
:relative;
top
:-50%;left:-50%;
}

-->
</style>
</head>

<body>
    
<div>
        
<span>
            
<img src=http://images.sohu.com/uiue/sohu_logo/beijing2008/sohu.gif>
        
</span>
    
</div>
</body>
</html>
posted @ 2007-03-22 14:48 阿牛 阅读(1112) | 评论 (1)编辑