简体   繁体   English

居中图像在水平和垂直方向上都充当“弹出窗口”

[英]Centering image acting as an “popup” both horizontally AND vertically

I am working on an responsive mobile website with a max width of 640px. 我正在使用最大宽度为640px的自适应移动网站。

I have an picture of 640 x 1060 I want to use a "popup". 我有一张640 x 1060的图片,我想使用“弹出窗口”。

Since I already have an entire website with overlays etc the z-index needs to be 7 to overal everything. 由于我已经有一个带有覆盖层等的完整网站,因此z-index必须为7才能覆盖所有内容。

I want padding around the sides and an auto heigh depending on the device's resolution. 我想根据设备的分辨率在两侧进行填充并自动调整高度。 So for example either: 因此,例如:

Padding-left: 10px 
Padding-right-10px

or 要么

width: 95%

This while the height auto adjusts to keep aspect ratio. 高度自动调整以保持纵横比的同时。 All this while keeping the image both horizontal and vertically centered. 所有这些,同时保持图像水平和垂直居中。 (In the middle of the screen) (在屏幕中间)

The position needs to be fixed as I don't want the used to be able to scroll "past" the image, but rather, in their face and make them close it. 该位置需要fixed因为我不希望以前的用户能够滚动“粘贴”图像,而是要在他们的脸上使其闭合。

you can try: 你可以试试:

 position:fixed;
 top:50%;
 left:50%;
 transform: translate (-50%,-50%)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM