css实现div内图片上下左右居中

建站知识 2021-07-03 08:15www.168986.cn长沙网站建设


复制代码
代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd">http://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
<html xmlns="<a href="http://.w3./1999/xhtml">http://.w3./1999/xhtml</a>">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>纯css实现div容器内图片上下左右居中效果</title>
<style type="text/css">
{ margin:0; padding:0; list-style:none;}
img{ border:none;}</p> <p>.main{ width:600px; height:400px; margin:100px auto;text-align:center;vertical-align:middle;display:block;position:relative; background:#ddd;}
.main a{display:table-cell;vertical-align:middle;width:600px; height:400px; }
.main a img{max-width:600px;max-height:400px; }
</style>
</head></p> <p><body>
<div class="main">
<img src="<a href="//img.jbzj./file_images/article/201401/2014010513525079.jpg">//img.jbzj./file_images/article/201401/2014010513525079.jpg</a>" />
</div>
</body>
</html>

兼容IE8,火狐,Chrome,Opera等浏览器

Copyright © 2016-2025 www.168986.cn 狼蚁网络 版权所有 Power by