html - 带边距的全屏居中 div

标签 html css overflow

我不知道如何将全屏 div 居中。 我想将 width: 90%height: 90% 的 div 居中,但是当我使用此代码时:

html,
body {
  width: 100%;
  height: 100%;
}

.outer {
  height: 100%;
  position: relative;
  text-align: center;
  width: 100%;
}

.inner {
  height: 90%;
  width: 90%;
  position: relative;
  top: 5%;
  background: red;
  margin: 0 auto;
}
<div class="outer">
  <div class="inner">

  </div>
</div>

我得到了一些我不想要的滚动条。

最佳答案

使用这个:

html,body {
    margin: 0;
   //other codes...
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
}

.outer {
    height: 100%;
    position: relative;
    text-align: center;
    width: 100%;
}

.inner {
    height: 90%;
    width: 90%;
    position: relative;
    top: 5%;
    background: red;
    margin: 0 auto;
}
<div class="outer">
    <div class="inner">

    </div>
</div>

关于html - 带边距的全屏居中 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50257707/

相关文章:

css - 当网格元素与末尾/底部对齐时滚动不起作用

CSS水平菜单链接问题

c++ - 如何检测 c/c++ 程序中可能/潜在的堆栈溢出问题?

html - 如何正确放置 <aside> 标签?

javascript - 如何从 getCurrentPosition() 获取坐标

css - RichFaces 选择列表 : Fluid scrollable list/column

html - 仅使用 CSS 渐变创建立方体

javascript - 为什么 IE11 对减号的 Node.normalize() 处理不正确?

html - 如何保持事件链接的颜色不变,直到我按下其他链接

javascript - 有什么方法可以在 css 中设计一个看起来完全像 html 下拉菜单的菜单