我試圖在屏幕上居中橫向和縱向的div,但不知何故它略微偏離中心。這是爲什麼?我認爲這是因爲內容的,但我不知道:dDiv偏離中心
我用
height:90%;
和
margin-top:5%
使其居中。
下面是完整的代碼: http://jsfiddle.net/7mNue/1/
我試圖在屏幕上居中橫向和縱向的div,但不知何故它略微偏離中心。這是爲什麼?我認爲這是因爲內容的,但我不知道:dDiv偏離中心
我用
height:90%;
和
margin-top:5%
使其居中。
下面是完整的代碼: http://jsfiddle.net/7mNue/1/
盪滌標記一點,在父DIV.container
(見下面的鏈接,特別是)應用display: flex
,並用center
柔性CSS屬性。
.container {
display: flex;
justify-content: center;
align-items: center;
}
.inlineflex {
display: inline-flex;
}
你可能會面臨在IE10的問題及以下,其他瀏覽器都好(見caniuse鏈接)
參考:在項目
在DIV
應用margin: auto
並設置一個全尺寸(width
& height
)。
試試這個
.popup{
width:100%; // remove this and add below style
max-width:100%;
}
.popup img{
max-width:100%;
}
不,對我不起作用 – virhonestum
box-sizing: border-box
有保證金和填補應該整理出來
不,仍然離中心 – virhonestum