我有一个使用 nano-scroller 的指令,它应该有一些固定的高度。 结构是这样的:
<div id="parent_div">
<my-custom-directive>
<div>...</div>
<div id="div_required_to_have_fixed_height">...</div>
</my-custom-directive>
</div>
我想在带有 id-div_required_to_have_fixed_height 的 div 中设置一些固定高度。样式高度参数可以在第一个 id 为 -parent_div 的 div 中提供。 所以在 div div_required_to_have_fixed_height 中,我想检查父级别是否存在高度,然后使用它,否则使用 height:500px
有没有办法使用 angular/css 来实现这一点。
最佳答案
要完成您正在寻找的内容,我建议您尝试使用 min-height CSS 属性。
在你的情况下 min-height:500px;
此时,您可以在 DOMContentLoaded
上添加事件监听器以确定是否需要调整高度。
类似于:
document.addEventListener("DOMContentLoaded", function(event) {
console.log("DOM fully loaded and parsed");
//here you can invoke a function to check the parent div
});
关于javascript - 检查父 div 是否有高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45938214/