我试图在屏幕上居中横向和纵向的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