[英]$(window)on.('load') Function Works on Firefox, but Not on Safari/iOS or Chrome?
[英]centering in browser window, works in safari but not firefox or chrome
無論頁面滾動到何處,我都需要一個彈出窗口位於瀏覽器窗口的中心。 窗口函數與jquery一起使用。 這在Safari中有效,但在其他瀏覽器中無效:
#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的內部,而不僅僅是外部使其位於左側/頂部,然后您期望成為。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.