当前位置: 动力学知识库 > 问答 > 编程问答 >

html - How do I center an image vertically within a div that is position:fixed?

问题描述:

This question already has an answer here:

  • vertical align center image in fixed size div

    6 answers

网友答案:

The easiest way is to set it as a background image:

#lightbox {
  background:url(myimage.jpg) no-repeat center center
}

Alternatively, you could use flexbox if you don't need to support IE <= 9

#lightbox {
  display: flex;
}
#lightbox img {
  align-items:  center;
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: