CSS 顶部和底部对齐

标签 css height positioning

尝试通过相对/绝对定位和 float 来实现这一点

                 Col1                         Col2
------------------------------------------------------------
-  H1 Content aligned to top          - Some Content       -
-                                     -                    -
-                                     -                    -
-                                     -                    -
-                                     -                    -
-                                     -                    -
-                                     -                    -
- Some other content aligned to bot   -                    -
------------------------------------------------------------

Col2 驱动 Col1 的高度

当我对 Col1 中的元素使用绝对位置时,我要么得不到 col1 中的高度,要么 col2 最终与 Col1 重叠

有什么帮助吗?

谢谢

最佳答案

我的最佳解决方案是使用固定高度的容器:

<div id="news">
  <div class="news-panel" id="left-news">
    <h2>Side Header</h2>
  </div>
  <div id="footer-news">
    <h2>Side Footer</h2>
  </div>
  <div class="news-panel" id="right-news">
    Main Content
  </div>
</div>

div#news { margin: 0px auto; position: relative; width: 895px; height: 208px; border: 1px solid gray; }
div#news div.news-panel { position: absolute; top: 0; }
div#news div#footer-news { position: absolute; bottom: 0; }
div#news div#left-news { left: 0; margin-right: 60px; width: 390px; border: 1px solid red; }
div#news div#right-news { width: 437px; right: 0px; }

虽然我不希望指定高度 - 但它可以正常工作(请参阅“发生了什么”部分):AgileApps

关于CSS 顶部和底部对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4785143/

相关文章:

html - 100% 高度的 float 页脚?

html - 输入标签后面的位置标签

html - 无法将此文本移至左侧

jquery - 拥有 'position:fixed'(始终位于顶部)div 的最简单的 jQuery 方法是什么?

html - 溢出:隐藏;不能在带有 IFRAME 的 Chrome 上运行?

jquery数据表更改默认最小高度

javascript - 同时使用 onepage-scroll.js 和 scrollReveal.js

qt - QPushButton 100% QGridLayout 单元格的高度

c# - 在 asp.net 中动态加载 css?

javascript - 来自包含的 div 中的意外 jquery 事件行为