css – 中心图像垂直/水平在另一个没有尺寸

前端之家收集整理的这篇文章主要介绍了css – 中心图像垂直/水平在另一个没有尺寸前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图让图像看起来有一个以中心为单位的播放按钮.我不知道主图像的确切尺寸,因为它是动态生成的.

现在,重叠图像(播放按钮)位于左上角.播放按钮如何显示水平和垂直居中?

谢谢.

  1. <div class="videoBox">
  2. <img src="/mainimage.png">
  3. <span></span>
  4. </div>
  5.  
  6. .videoBox { position: relative; }
  7.  
  8. .videoBox span {
  9. position:absolute;
  10. left: 0px;
  11. bottom: 0px;
  12. width: 100%;
  13. height: 100%;
  14. z-index: 1;
  15. background: transparent url(../img/elements/playbutton.png) no-repeat;
  16. }

解决方法

  1. .videoBox span {
  2. display: block;
  3. position: absolute;
  4. top: 0;
  5. left: 0;
  6. bottom: 0;
  7. right: 0;
  8. z-index: 1;
  9. background: url(../img/elements/playbutton.png) no-repeat center center;
  10. }

猜你在找的CSS相关文章