Javascript 以浏览器窗口为中心,适用于safari,但不适用于firefox或chrome
我需要一个弹出窗口在浏览器窗口中居中,无论页面滚动到何处。窗口函数与jquery一起使用。这适用于Safari,但不适用于其他浏览器:Javascript 以浏览器窗口为中心,适用于safari,但不适用于firefox或chrome,javascript,jquery,css,browser,centering,Javascript,Jquery,Css,Browser,Centering,我需要一个弹出窗口在浏览器窗口中居中,无论页面滚动到何处。窗口函数与jquery一起使用。这适用于Safari,但不适用于其他浏览器: #infoBox1, #infoBox2, #infoBox3, #infoBox4 { position: fixed; display: none; width: 70%; height: auto; top: 30%; left: 50%; margin: -15% -35% 0 -35%;
#infoBox1, #infoBox2, #infoBox3, #infoBox4 {
position: fixed;
display: none;
width: 70%;
height: auto;
top: 30%;
left: 50%;
margin: -15% -35% 0 -35%;
z-index: 400;
}
如有任何建议,将不胜感激 可以使用以下方法将图元居中:
.div {
position:absolute; // or use fixed;
left:50%;
top:50%;
transform: translate(-50%, -50%);
}
试试这个,
希望这有帮助
#infoBox1, #infoBox2, #infoBox3, #infoBox4 {
position: fixed;
display: none;
width: 70%;
height: auto;
top: 50%;
left: 50%;
z-index: 400;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
这应该可以做到:
#infoBox1, #infoBox2, #infoBox3, #infoBox4 {
position: fixed;
display: none;
width: 70%;
height: auto;
left:50%;
top:50%;
transform: translate(-50%, -50%);
z-index: 400;
}
transform:translate(-50%,-50%)
将确保left 50%
和top 50%
将从所选div的内部获取,而不仅仅是外部,使其比您期望的更向左/向上。left:0;正确的;0; 左边距:自动;右边距:自动;利润率最高:15%;