zoukankan      html  css  js  c++  java
  • 图片在容器里垂直居中

    在div-css布局运用中,如何让图片在容器里垂直居中是很多人询问的问题,这里收集了几个例子

    第一个例子

    <!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;    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> </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"> <!-- 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>
    提示:您可以先修改部分代码再运行

    背景图片的方法

    <!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;border:1px solid #666;    height:500px;    background:url("http://www.google.com/intl/en/images/logo.gif") center no-repeat } --> </style> </head> <body> <div></div> </body> </html>
    提示:您可以先修改部分代码再运行
  • 相关阅读:
    经典矩阵快速幂之一-----poj3233(矩阵套矩阵
    hdu 2588(简单的欧拉
    新能源汽车无线充电管理网站1
    结对项目:黄金点游戏(何珠&赵艳)
    WC项目,实现一个统计程序
    简单四则运算
    在一周之内,快速看完整部教材,列出你不懂的5-10个问题。
    博客作业——创建个人技术博客(建议在cnblogs.com上创建),并写一个自我介绍,列出你对这门课的希望和自己的目标。同时具体列出你计划每周花多少时间在这门课上(包括上课时间)。
    能自动生成小学四则运算题目
    在一周之内,快速看完整部教材,列出你不懂的5-10个问题。
  • 原文地址:https://www.cnblogs.com/tangself/p/1655590.html
Copyright © 2011-2022 走看看