第一种: 作为元素背景图片
<style>
#app{
width: 500px;
height: 500px;
background: #ccc url('../../../static/images/demo.png') no-repeat center center;
}
</style>
<div id="app"></div>
第二种: img标签方式
<style>
#app{
width:500px;
height: 500px;
display:flex;
justify-content:center;
align-items:center;
}
</style>
<div id="app">
<img src="../../../static/images/demo.png">
</div>
- 2:display:table-cell + vertical-align :middle
<style>
#app{
width:500px;
height: 500px;
text-align:center;
display:table-cell;
vertical-align:middle
}
</style>
<div id="app">
<img src="../../../static/images/demo.png">
</div>
<style>
#app{
width:500px;
height: 500px;
position:relative
}
img{
position:relative;
top:50%;
left:50%;
transform:translate(-50%,-50%)
}
</style>
<div id="app">
<img src="../../../static/images/demo.png">
</div>
<style>
#app{
width:500px;
height: 500px;
text-align:center
}
span{
display:inline-block;
height:100%;
vertical-align:middle
}
img{
vertical-align:middle
}
</style>
<div id="app">
<span></span>
<img src="../../../static/images/demo.png">
</div>