Css Div稍微偏离中心
我试图在屏幕上水平和垂直居中放置一个div,但不知怎么的,它有点偏离中心。为什么呢?我想是因为内容,但我不知道:D 我曾经Css Div稍微偏离中心,css,html,center,Css,Html,Center,我试图在屏幕上水平和垂直居中放置一个div,但不知怎么的,它有点偏离中心。为什么呢?我想是因为内容,但我不知道:D 我曾经 height:90%; 及 把它放在中间 以下是完整的代码: 应用边距:自动并在DIV上设置全尺寸(宽度和高度) .popup{ width:100%; // remove this and add below style max-width:100%; } .popup img{ max-width:100%; } 稍微清理一下标记,并在父
height:90%;
及
把它放在中间
以下是完整的代码:
应用
边距:自动并在DIV
上设置全尺寸(宽度
和高度
)
.popup{
width:100%; // remove this and add below style
max-width:100%;
}
.popup img{
max-width:100%;
}
稍微清理一下标记,并在父级DIV.container
中应用display:flex
(特别请参见下面的链接),并使用center
flex CSS属性
.container {
display: flex;
justify-content: center;
align-items: center;
}
.inlineflex {
display: inline-flex;
}
您可能会在IE10及以下版本中遇到问题,其他浏览器都很好(请参阅caniuse链接)
参考资料:
框大小:有边距和填充的项目上的边框框应进行分类不,仍然偏离中心
.container {
display: flex;
justify-content: center;
align-items: center;
}
.inlineflex {
display: inline-flex;
}