如何让图片相对于上层DIV始终保持水平、垂直都居中
(编辑:jimmy 日期: 2024/11/1 浏览:2)
复制代码代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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">
.thumbBox {width:260px; height:260px; text-align:center; vertical-align:middle; display:table-cell; border:1px solid red;}
</style>
</head>
<body>
使图片相对于上层DIV始终水平、垂直都居中
<p>示例一</p>
<div class="thumbBox">
<img src="/UploadFiles/2021-03-30/bdlogo.gif"></div>
<p>示例二</p>
<div class="thumbBox">
<img src="/UploadFiles/2021-03-30/cb32ecdc7d0def4d123ae4c38c50050b.jpg"></div>
</body>
</html>