首页 > 代码库 > 关于图片在div中居中问题

关于图片在div中居中问题

 

    ①作为背景图片
       
 1  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2             <html xmlns="http://www.w3.org/1999/xhtml">
 3             <head>
 4             <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
 5             <title>无标题文档</title>
 6             <style>
 7             .img{
 8               overflow: auto;
 9               text-align: center;
10               height: 200px;width: 90%;
11               margin:0 auto 20px;
12               border-radius: 0px; 
13               background-repeat: no-repeat;
14               background-position: center top;
15               -webkit-background-size: 100% 150px;
16               background-size:  100% 200px;
17               border:1px solid red;
18             }
19             </style>
20             </head>
21  
22             <body>
23             <div class="img" style="background-image:url(../image/5.png)">
24  
25             </div>
26             <script>
27  
28             </script>
29             </body>
30             </html>
    ②作为普通图片
 
 

关于图片在div中居中问题