html - 如何将内容保留在 View 中?

标签 html css

我目前有一个容器和一个内容。

如何将内容保留在浏览器中?

代码如下:

      <h1>
        Content inside
      </h1>

最佳答案

通过简单地添加到 body

overflow: hidden;

并确保使用

box-sizing: border-box;

或删除 width:100%;

box-sizing:border-box; 修复了 100% 宽度填充的问题 - 将填充放在元素的框模型中。

*{margin:0;box-sizing:border-box;}
html,body{height:100%;font:14px/1.4 sans-serif;}

body{overflow:hidden;}

#container {
  background-color: white;
  min-height: 100%;
  padding: 30px; 
}
  <div id="container">
      <h1>
        Content inside
      </h1>
      <div>
        I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. I currently have a container and a content inside. When the browser gets minimized, the content inside overflows, and the scroll bars appear. 
      </div>
  </div>

jsBin demo

关于html - 如何将内容保留在 View 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40328086/

相关文章:

html - 最后一个子选择器不工作

html - 匹配 CSS 规则的正则表达式

html - 我想在我的 Logo 旁边的标题中显示我的导航栏

html - 为 <div> 着色以覆盖具有 float 子元素的网页的整个宽度,<div>

html - 将 HTML/CSS 转换为纯 HTML

javascript - 如何获取innerHTML中的原始html字符串?

html - CSS 悬停、z-index 和 div

javascript - 将 JavaScript 变量传递到 HTML 输入框并(在 PHP 文件中使用)

javascript - 如何正确地将具有多个元素的新对象推送到数组中?

html - 固定位置在 Chrome 中不起作用