【发布时间】:2018-04-01 23:52:36
【问题描述】:
如何在背景上垂直和水平居中图像?
我有这个代码:
.lineargradientgreen {
background-image: linear-gradient(green, white);
border-width: 2pt 2pt 2pt 2pt;
height: 500px;
width: 500px;
float: left;
text-align: center;
}
.lineargradientblue {
background-image: linear-gradient(to top left, white, blue);
border-width: 2pt 2pt 2pt 2pt;
height: 500px;
width: 500px;
float: left;
text-align: center;
}
<div class="lineargradientgreen">
<img src="https://www.listefit.com/wp-content/uploads/2017/12/tiny-png-google-g%C3%B6rsel-optimizasyonu.jpg" alt="Hot Air Balloon" width="200px" height="200px" />
</div>
<div class="lineargradientblue">
<img src="https://www.samcodes.co.uk/project/geometrize-haxe-web/assets/images/xseagull.jpg.pagespeed.ic.iK66EGA15-.jpg" alt="Hot Air Balloon" width="200px" height="200px" />
</div>
最后,我得到的图像只在两个背景上水平居中,我怎样才能让它们垂直居中?
【问题讨论】: