html - 在 2 个固定 block 之间创建一个 block

标签 html css

这是一个嵌入了 Electron 的 Angular 应用程序。
我有 2 个积木

  • title-bar position: fixed
  • 导航栏 position: fixed

我想要一个由剩余的宽度高度分隔的内容区域。这是我的代码:

#app-content {
  position: fixed;
  margin-left: 27px;
  margin-top: 20px;
  width: 100%;
  height: 100%;
  overflow: auto;
  border:5px solid #ce2e2e;
  background-color: white;
}
<app-title-bar></app-title-bar>
<app-navigation-bar></app-navigation-bar>
<div id="app-content">
  <router-outlet></router-outlet>
</div>

我得到了以下结果。左边距和顶部边距使 block 在底部和右侧溢出。 我该如何解决?我已经尝试将边距放在底部和右侧,但没有任何反应。

app

最佳答案

使用box-sizing: border-box;将边框包含在100%宽高中,使用calc(...) widthheight 如下所示,将您的边距包括在 100% 中:

html, body {
 margin: 0;
}
#app-content {
  position: fixed;
  box-sizing: border-box;
  margin-left: 27px;
  margin-top: 20px;
  width: calc(100% - 27px);
  height: calc(100% - 20px);
  overflow: auto;
  border:5px solid #ce2e2e;
  background-color: white;
}
<app-title-bar></app-title-bar>
<app-navigation-bar></app-navigation-bar>
<div id="app-content">
  <router-outlet></router-outlet>
</div>

关于html - 在 2 个固定 block 之间创建一个 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57498375/

相关文章:

html - 为什么在这种情况下我必须使用 !important ?

javascript - 获取动态文本的值并将其传递给输入值

javascript - 用 jquery 添加一个复选框到一个 div

html - 将 <br> 替换为使其宽度适应容器 : possible? 的水平线

html - CSS 边框渲染优先级

css - 元素是我的组件没有以统一的方式发送

html - 保持对背景图像的响应以及完整的拖放元素并响应背景图像

php - 图片大小调整php代码

ios - 用于 iPhone 的 HTML 文本链接向多个号码发送短信

javascript - AngularJS 路由和模型——我在正确的轨道上吗?