设置图片位于div正中间


最忌总结了几种居中图片的方法,跟大家分享一下,有什么总结不到位的还请大神多多指点。

1、利用弹性布局居中图片,兼容IE9以上浏览器

<div style="width: 400px;height: 400px;background-color: blue;display: flex;align-items: center;justify-content: center;">
			<img src="img/develop.png" style="width: 100px;height: 100px;background-color: red;" />
		</div>
align-items: center;表示垂直居中,justify-content: center;表示水平居中。

2、兼容IE8的居中方式

<div style="width: 400px;height: 400px;background-color: blue;line-height: 440px;text-align: center;">
			<img src="img/develop.png" style="width: 100px;height: 100px;background-color: red;margin: 0 auto;" />
		</div>

3、兼容IE6的居中方式

<div style="width: 400px;height: 400px;background-color: blue;position: relative;">
			<img src="img/develop.png" style="width: 100px;height: 100px;background-color: red;display: inline-block;position: absolute;top: 50%;left:50%;margin-top: -50px;margin-left: -50px;" />
		</div>

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM