javascript - 不向标题添加高度我们可以修复布局吗

标签 javascript jquery html css

下面是我的 CSS & HTML 这里是我的 fiddle ,在标题中我使用 50px 高度的地方,有什么方法不需要在标题中添加高度并且布局仍然适合所有页面

* {
  box-sizing: border-box;
}

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

#page {
  height: 100%;
}

#header {
  height: 50px;
  background: yellow;
}

#content {
  height: calc(100% - 100px);
  background: grey;
  overflow: auto;
}

#footer {
  height: 50px;
  background: blue;
}
<div id="page">
  <div id="header">Header</div>
  <div id="content">
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
      has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
      has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
  </div>
  <div id="footer">Footer</div>
</div>

最佳答案

这可能对你有帮助,

 $(document).ready(function() {
    //Get the Outer height of the header
    var headerHeight = $('#header').outerHeight();
    //Add the same height to the content as padding top.    
    $('#content').css('padding-top', headerHeight); 
});

关于javascript - 不向标题添加高度我们可以修复布局吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40169755/

相关文章:

javascript - 如何导入自定义 ES6 模块?

javascript - 将二维数组填充到表中(输出所有可能的组合)

javascript - 如何仅为 Material 纹理设置透明度/不透明度

javascript - Bootstrap 3 折叠菜单未在 Wordpress 中展开

javascript - 获取文本区域中距光标最近的某个字符

javascript - 在视频标签之前加载图片标签

javascript - 打开 md-calendar 时滚动到当前日期

JQuery 获取子字符串?

html - CSS:响应式布局中的高度自动问题

html - HTML5 Canvas 的大小和分辨率有什么关系