Home  >  Article  >  Web Front-end  >  css实现图片在div中垂直水平居中代码实例_html/css_WEB-ITnose

css实现图片在div中垂直水平居中代码实例_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:30:181071browse

css实现图片在div中垂直水平居中代码实例:
让图片在一个元素中垂直水平居中这样的需求在实际应用中还是很多的,下面就通过代码实例介绍一下如何实现此效果。
代码实例如下:

 

<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>蚂蚁部落</title> <style type="text/css"> div{  width:500px;  height:500px;  border:1px solid red;  display:table-cell;  text-align:center;  vertical-align:middle;}</style></head><body><div><img  src="tree.jpg"/ alt="css实现图片在div中垂直水平居中代码实例_html/css_WEB-ITnose" ></div></body></html>

 

以上代码可以实现图片的水平垂直效果,可能低版本的IE7浏览器不支持,不过在不远的未来都不是问题。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=12956

更多内容可以参阅:http://www.softwhy.com/divcss/

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn