100%高度div的主要问题

发布于 2024-10-14 18:28:19 字数 737 浏览 4 评论 0原文

在此处输入图像描述

/* Left menu */
.leftMenu{
    width: 200px;
    border:2px solid green;
    float:left;
    background-color:#c0c0c0;
}

/* Main Content area */
.mainBox{
    border:2px solid red;
    background-color: #ffffff;
}
.mainWrapper{
    border:2px solid white;
}

如何让

<div class="mainWrapper">
    <div class="leftMenu">
        left
    </div>
    <div class="mainBox">
        main<br /><br /><br /><br /><br />
    </div>        
    <div class="clear"></div>
</div>

火焰将左侧菜单延伸到底部?

请注意,我尝试过人造柱,但它们不起作用,因为出于某种原因白色主框位于前面。

enter image description here

/* Left menu */
.leftMenu{
    width: 200px;
    border:2px solid green;
    float:left;
    background-color:#c0c0c0;
}

/* Main Content area */
.mainBox{
    border:2px solid red;
    background-color: #ffffff;
}
.mainWrapper{
    border:2px solid white;
}

With

<div class="mainWrapper">
    <div class="leftMenu">
        left
    </div>
    <div class="mainBox">
        main<br /><br /><br /><br /><br />
    </div>        
    <div class="clear"></div>
</div>

How the blazes do I get the left menu to extend to the bottom?

Please note I've tried faux columns but they just don't work as the white main box just is at the front for some reason.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

东走西顾 2024-10-21 18:28:20

这又如何呢?

http://jsfiddle.net/PH3t2/

我添加了 postion:absolutetop:0bottom:0 到你的左侧菜单

我已经给了 mainBox padding-left: 205px

我已经给了 mainWrapper position:relative

请随意向 mainBox 添加内容,以查看 leftMenu 也会增长。


要完成此操作并使其在 IE6 中工作,请添加:

.leftMenu, .mainBox {
    min-height: 250px;
    height: auto !important;
    height: 250px;
}

What about this?

http://jsfiddle.net/PH3t2/

I've added postion:absolute , top:0 and bottom:0 to your leftmenu

I've given mainBox padding-left: 205px

I've given mainWrapper position:relative

Feel free to add content to mainBox to see that leftMenu grows as well.


To finish this off and make it work in IE6, add:

.leftMenu, .mainBox {
    min-height: 250px;
    height: auto !important;
    height: 250px;
}
时光磨忆 2024-10-21 18:28:20

使用假列时,需要将背景图片设置为.mainWrapper。

将 .mainBox 背景设置为透明,并将 .mainWrapper 背景设置为左侧 200px 灰色,所有其他宽度设置为白色。

When using faux columns, you need to set background image to .mainWrapper.

Set .mainBox background to transparent and make .mainWrapper background as 200px gray at left side and all other width to white.

指尖凝香 2024-10-21 18:28:19

您需要为 .mainWrapper 设置固定高度,例如 100px;然后将 .leftMenu 的高度设置为 100%;

编辑: 根据您的评论,我不确定是否可以使用纯 css 。如果 JavaScript 解决方案可以接受,那么您可以使用 jquery 和以下代码:

$(document).ready(function(){
    $('.leftMenu').css("height",$('.mainWrapper').height());
});

实例: http ://jsbin.com/udowu4/2

you need set a fixed height for the .mainWrapper for example 100px; and then you set the height of .leftMenu to 100%;

Edit: According your comment, I am not sure if it possible with pure css. If it's acceptable a javascript solution then you can use jquery and the following code:

$(document).ready(function(){
    $('.leftMenu').css("height",$('.mainWrapper').height());
});

Live example: http://jsbin.com/udowu4/2

紫﹏色ふ单纯 2024-10-21 18:28:19

CSS 仿列是最好的解决方案。以下解决方案可能有效,但最终可能会遇到其他问题。注意:无论哪一列更高,这都有效。

.leftMenu {
  width: 200px;
  float: left;
  background-color: #C0C0C0; /* C0C0C0 is used for demonstration
                                ideally this should be same as the
                                border color used in the next style */
}
.mainBox {
  border-left: 200px solid #CCCCCC;
}
.mainWrapper {
  border: 2px solid #000000;
  background-color: #F8F8F8; /* this should be set to the color that displays
                                behind mainBox; its best to set it here in case
                                the left column becomes taller than main column */
}
<div class="mainWrapper">
  <div class="leftMenu">left</div>
  <div class="mainBox">
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main
  </div>
  <div class="clear"></div>
</div>

CSS Faux columns is the best possible solution. The following solution might work but you could end up with other problems. Note: This works regardless of which column is taller.

.leftMenu {
  width: 200px;
  float: left;
  background-color: #C0C0C0; /* C0C0C0 is used for demonstration
                                ideally this should be same as the
                                border color used in the next style */
}
.mainBox {
  border-left: 200px solid #CCCCCC;
}
.mainWrapper {
  border: 2px solid #000000;
  background-color: #F8F8F8; /* this should be set to the color that displays
                                behind mainBox; its best to set it here in case
                                the left column becomes taller than main column */
}
<div class="mainWrapper">
  <div class="leftMenu">left</div>
  <div class="mainBox">
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main<br>
    main
  </div>
  <div class="clear"></div>
</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文