zoukankan      html  css  js  c++  java
  • Div垂直居中及容器内图片垂直居中的CSS解决方法

    Div垂直居中及容器内图片垂直居中的CSS解决方法

    http://axl234.iteye.com/blog/781094

        Div与CSS布局,最让人头疼的就是容器内的东西如何垂直居中的问题,我总结出以下居中办法,兼容IE与及Firefox 方法一 <style type="text/css"> <!-- * {margin:0;padding:0} div {   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 } div {   500px;   height:500px;   line-height:500px;   border:1px solid #666;   overflow:hidden;   position:relative;   text-align:center; } div p {   position:static;   +position:absolute;   top:50% } img {   position:static;   +position:relative;   top:-50%;left:-50%;   vertical-align:middle } p:after {   content:".";font-size:1px;   visibility:hidden } --> </style> </head> <body> <div><p><img src="http://www.google.com/intl/en/images/logo.gif" /></p></div> </body> </html>
    方法三
    <!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"> <!-- * {margin:0;padding:0} div {   500px;   height:500px;   line-height:500px;   border:1px solid #666;   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%;   vertical-align:middle } --> </style> </head> <body> <div><p><img src="http://www.google.com/intl/en/images/logo.gif" /></p></div> </body> </html>
  • 相关阅读:
    Win10怎么设置虚拟内存?
    树莓派 —— USB 摄像头简单测试 (拍照 & 视频)
    如何设置树莓派 VNC 的分辨率
    树莓派 VNC Viewer 远程桌面配置教程
    数据库开发——MySQL——数据的增删改查
    数据库开发——MySQL——foreign key
    数据库开发——MySQL——primary key
    一种关闭按钮
    oracle下 启动subversion命令 及 oracle相关服务启动备忘
    table内 获取同一行 其他列的value
  • 原文地址:https://www.cnblogs.com/tabcdt/p/2738047.html
Copyright © 2011-2022 走看看