<body style="min-height:2000px;">
    <div id="test" style="position:relative;bottom:0;">
         some dynamically changed content
    </div>
</body>

What do i expect:
-If #test height is greater or equal to body's it should stick to bottom (as it happens now cuz of block model)
-If #test height is less than body's it should however stick to bottom, having white space above it. (which doesn't happen, #test doesn't stick to bottom).

我期待什么: - 如果#test高度大于或等于身体,它应该坚持到底部(因为它现在发生块模型) - 如果#test高度小于身体,它应该坚持到底部,有白色空间它上面。 (这不会发生,#test不会坚持到底)。

-Using position:absolute is not acceptable as then #test will not influence body height when #test is higher than body.
-Using position:fixed is not acceptable as then #test will stick to bottom of window, not body.

- 使用位置:绝对是不可接受的,因为当#test高于body时,#test不会影响身高。 - 使用位置:固定是不可接受的,因为#test将坚持窗口的底部,而不是身体。

Q: Can I get what I expect using css only? How?

问:我可以使用css获得我期望的结果吗?怎么样?

Sorry for poor English, however I think the question is easy to understand.
Thank you.

对不起英语不好,但我觉得这个问题很容易理解。谢谢。

P.S.: I need that in css because some dynamically changed content is changed via js and I want to avoid recalculating #test div position each time it changes.

P.S。:我在css中需要它,因为一些动态改变的内容是通过js改变的,我想避免每次改变时重新计算#test div位置。

UPD:

I've also tried some display:inline-block; vertical-align:bottom; stuff still no result.

我也试过一些显示:inline-block;垂直对齐:底部;东西仍然没有结果。

UPD2:

Thank you guys, still it seems, that easiest way is just to add a couple of lines to my javascript to recalculate body height on #test height change.

谢谢你们,似乎仍然是,最简单的方法就是在我的javascript中添加几行来重新计算#test高度变化时的身高。

11 个解决方案

#1


8

Because of the dynamic height nature of #test you cannot do this with CSS alone. However, if you're already using jQuery, a quick .height() call should be able to get you what you need (#test height needs to be subtracted from positioning it 2000px from the top).

由于#test的动态高度特性,单独使用CSS无法做到这一点。但是,如果您已经在使用jQuery,那么快速.height()调用应该能够满足您的需求(#test高度需要从顶部定位2000px中减去)。

<style>
body {
    min-height: 2000px;
}

#test {
    position: relative;
    top: 2000px;
} 
</style>

<script>
var testHeight = $("#test").height();
$( "#test" ).css({
    margin-top: -testHeight;
});
</script>

更多相关文章

  1. IFrame中的Div没有达到给定的高度
  2. Chrome 50更改隐式表格单元格高度行为
  3. 两个堆叠DIV的顶部DIV如何影响另一个DIV的高度
  4. CSS:浮动时忽略div高度
  5. DiggBar如何基于不在其域上的内容动态调整其iframe的高度?
  6. 当使用opendkim在MTA签名时,DKIM失败(身体哈希)。
  7. Div高度为图像高度,图像宽度为div宽度
  8. 在textarea上应用0高度div的类
  9. 扩展子div时如何扩展容器div的高度

随机推荐

  1. Android webkit image的加载过程解析(二)
  2. Android官方技术文档翻译——Gradle 插件
  3. 获取Android的Java源代码并在Eclipse中关
  4. 当Google忙着忽悠Android的时候,各位别忘
  5. Android 中文API合集 chm版,电子书籍下载
  6. Android 中文 API――android.widget合集
  7. android 自定义组件 :对VelocityTracker的
  8. Android(安卓)SQLite使用详解和多线程并
  9. android基础入门(二)――创建android工程
  10. 2010-11-4