css实现div内图片上下左右居中
网站建设 2021-07-03 08:15www.dzhlxh.cn网站建设
复制代码
代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
<html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/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.com/file_images/article/201401/2014010513525079.jpg">//img.jbzj.com/file_images/article/201401/2014010513525079.jpg</a>" />
</div>
</body>
</html>
兼容IE8,火狐,Chrome,Opera等浏览器
上一篇:css调用服务器端字体示例代码
下一篇:下拉框select样式改写具体实现