html - 在 2 个固定块之间创建一个块
问题描述
这是一个嵌入电子的角度应用程序。
我有 2 个街区
- 一个标题栏
position: fixed
- 一个导航栏
position: fixed
我想有一个由width
and的其余部分分隔的内容区域height
。这是我的代码:
#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>
我有以下结果。左右边距使块在底部和右侧溢出。我该如何解决?我已经尝试将边距放在底部和右侧,但没有任何反应。
解决方案
用于box-sizing: border-box;
将边框包含在 100% 的宽度和高度中,并使用calc(...)
forwidth
和height
如下所示将您的边距包含在 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>
推荐阅读
- postgresql - 如何使用 min(date_field) 过滤数据 - postgres
- windows - XAML 控件库中的控件示例变为圆角。为什么以及如何?
- elixir - 有没有其他方法可以在 Windows 8 中安装 elixir/Phoenix
- regex - 如何使用正则表达式替换替换特殊字符?
- android - 使用 TextEditingController 更改文本时,键盘的清除按钮不起作用
- python - 在antlr4 python target中获取同一行中多个ID的列号信息
- javascript - 使用标记突出显示传单中的区域?
- css - 获取 SVG 内文本元素的左侧和顶部?
- pandas - 熊猫数据框适用于多列
- scala - 读取一个大的 csv 文件并根据条件使用 scala / spark 将其分离