【问题标题】:jQuery css height increases but does not decrease, Foundation, FlexjQuery css高度增加但不减少,Foundation,Flex
【发布时间】:2018-12-24 10:34:40
【问题描述】:

这是一支笔:https://codepen.io/anon/pen/LBNyXP?editors=1111

如果您更改视口的高度,高度会上升,但不会下降。我认为既然它可以增加,它应该也可以减少,但事实并非如此。

在“整页”模式下观看效果最佳:

$(document).ready(function() { 
  $(window).on('load resize', function() {
    var parentHeight = $('#parent').outerHeight();
    console.log('height', parentHeight);
    $('#grandchild').css('height', parentHeight);
  });
});
#parent {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}
#parent #child {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="parent">
  <div id="child">
    <div id="grandchild">Grandchild</div>
  </div>
</div>

【问题讨论】:

    标签: jquery flexbox zurb-foundation


    【解决方案1】:

    那是因为“#grandchild”有一个硬编码的高度,去掉硬编码的高度,它会根据可用的高度自行调整。

    【讨论】:

    • 硬编码 =/= 可以改变吗?我认为 jQuery 值会随着高度的变化而变化。难道不应该有办法在 jQuery 中做到这一点吗?
    • jQuery 的 .height() 将始终返回内容高度,并且在内容中,有带有硬编码高度的“#grandchild”。所以我认为在 jQuery 中没有办法做到这一点。
    猜你喜欢
    • 2012-05-30
    • 2018-01-21
    • 2021-08-16
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多