CSS图片垂直居中方法整理集合 !(常见问题解答)
2012-01-21 18:05
686 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <style type="text/css"> <!-- * {margin:0;padding:0} div { width:500px; height:500px; border:1px solid #ccc; 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%; width:276px; height:110px } --> </style> <div><p><img src="http://www.jb51.net/images/logo.gif" /></p></div>
标准浏览器下另类方法:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <style type="text/css"> <!-- body { margin:0;padding:0 } div { width:500px; height:500px; line-height:500px; border:1px solid #ccc; overflow:hidden; position:relative; text-align:center; margin:auto } div p { position:static; +position:absolute; top:50% } img { position:static; +position:relative; top:-50%;left:-50%; width:276px; height:110px; vertical-align:middle } p:after { content:".";font-size:1px; visibility:hidden } --> </style> <div><p><img src="http://www.jb51.net/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"> <style type="text/css"> <!-- * {margin:0;padding:0} div { width:500px; height:500px; line-height:500px; border:1px solid #ccc; overflow:hidden; position:relative; text-align:center; } div p { position:static; +position:absolute; top:50%; vertical-align:middle } img { position:static; +position:relative; top:-50%;left:-50%; width:276px; height:110px; vertical-align:middle } --> </style> <div><p><img src="http://www.jb51.net/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"> <style type="text/css"> * {margin:0;padding:0;} div { width:500px;text-align:center;border:1px solid #f00;line-height:500px; height:500px;font-size:500px } *>div{ font-size:12px } div img { vertical-align:middle } </style> <div> <img src="http://www.jb51.net/images/logo.gif" /> </div>
最简单当然是背景图片的方法拉。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <style type="text/css"> * {margin:0;padding:0;} div { width:500px;border:1px solid #f00; height:500px; background:url("http://www.jb51.net/images/logo.gif") center no-repeat } </style> <div> </div>
相关文章推荐
- [推荐] CSS图片垂直居中方法整理集合 !(常见问题解答)
- CSS图片垂直居中方法整理集合 !(常见问题解答)
- [教程] [推荐] CSS图片垂直居中方法整理集合 !(常见问题解答)
- CSS图片垂直居中方法整理集合 !
- CSS图片垂直居中方法整理集合
- CSS图片垂直居中方法整理集合
- CSS图片垂直居中方法整理集合 !
- 备忘:CSS图片垂直居中全兼容淫技整理集合
- CSS解决页面图片水平垂直居中问题的方法
- CSS垂直水平居中方法整理
- CSS中的内容垂直居中的常见的方法
- div+css解决图片垂直居中问题
- CSS 图片+文字,文字垂直居中问题
- CSS未知尺寸的图片在容器中垂直居中的方法
- CSS中图片水平垂直居中方法小结
- 常见css布局图片垂直居中
- CSS 图片在DIV中垂直居中的显示方法
- css-图片和文字垂直居中问题
- CSS 图片在DIV中垂直居中的方法
- 整理前端css/js/jq常见问题及解决方法(3)