垂直居中及容器内图片垂直居中的CSS解决方法
    Div与CSS布局,最让人头疼的就是容器内的东西如何垂直居中的问题,我在做站时也遇到,查了一下资料,总结出以下居中办法,兼容IE与及 Firefox!
方法一
- <style?type="text/css">??
 
- <!--? ??
 
- *?{margin:0;padding:0} ??
 
- div?{ ??
 
- ??width:500px; ??
 
- ??height:500px; ??
 
- ??border:1px?solid?#666; ??
 
- ??overflow:hidden; ??
 
- ??position:relative; ??
 
- ??display:table-cell; ??
 
- ??text-align:center; ??
 
- ??vertical-align:middle ??
 
- } ??
 
- div?p?{ ??
 
- ??position:static; ??
 
- ??+position:absolute; ??
 
- ??top:50% ??
 
- ??} ??
 
- img?{ ??
 
- ??position:static; ??
 
- ??+position:relative; ??
 
- ??top:-50%;left:-50%; ??
 
- ??} ??
 
- 
-->??
 
- 
</style>??
 
- 
<div><p><img?src="http://www.google.com/intl/en/images/logo.gif"?/></p></div>??
 
 
方法二
- <!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Strict//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">??
 
- 
<html?xmlns="http://www.w3.org/1999/xhtml">??
 
- 
<head>??
 
- 
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/>??
 
- 
<title>div里面图片垂直居中的几个例子</title>??
 
- 
<style?type="text/css">??
 
- <!--? ??
 
- body?{ ??
 
- ??margin:0;padding:0 ??
 
- 
                        
                    
 
 
                    
                    
                        免责声明: 本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。