javascript - 从Angular2中的另一个元素设置元素高度
问题描述
我在一个包含动态内容的部分中有两个 div。左侧容器包含一个数字列表和另一个输入字段列表。如果该容器延伸到 600px 的高度,我需要优先考虑输入字段的容器,我需要在我的数字容器上具有该高度,然后如果该元素超过 600px,则该元素进入单独的滚动。
<section>
<div class="numbers">
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
<div>1</div>
</div>
<div class="inputs">
<input type="text">
<input type="text">
<input type="text">
<input type="text">
</div>
</section>
section {
display: flex;
}
.numbers {
margin-right: 50px;
}
.numbers div {
background: black;
height: 20px;
width: 20px;
margin-bottom: 10px;
color: #fff;
}
.inputs {
display: flex;
flex-direction: column;
}
input {
margin-bottom: 20px;
}
解决方案
这是我对这个问题的解决方案,我创建了一个在 Oninit 中调用的函数以及更新内容的每个按钮,在 html 上我调用了它 [style.height.px]="elHeight - 100"
这是我的打字稿代码
getHeight() {
const leftEl = document.getElementById('number-col');
const rightEl = document.getElementById('question-col');
setTimeout(() => {
this.elHeight = rightEl.clientHeight;
}, 100);
}
推荐阅读
- json - 如何正确解析 SWIFT 中的 JSON 对象
- json - 从 Wagtail 流域中检索 blog_index_page 的第一张图像
- xcode - 没有Phonegap构建的Phonegap/Cordova到ipa文件
- python - 使用重复描述的单词使用 protobuf 元素的子属性
- c# - 在 2legged 上下文中使用 c# forge 包中的 x-user-id
- r - “for”循环内的 InputID
- reactjs - 如果 TextField 在材质 ui 中具有 Select 属性,则验证不起作用
- latex - 如何在新环境中包装 LaTex 命令
- ansible - vagrant ansible 访问其他机器IP地址
- java - 使用 JPA,方法需要 60 秒