0

JsFiddle:这里

所以我遇到了两个问题,我似乎无法找出解决方案。一:我需要内容div的最小高度为菜单的高度(我不喜欢使用最小高度规则)二:当内容div大于菜单时我需要菜单的高度为大小的内容 div。

HTML:

<div class="container">
    <div class="menu">
        <ul>
            <li>Menu1</li>
            <li>Menu2</li>
            <li>Menu3</li>
            <li>Menu4</li>
        </ul>
    </div> 
    <div class="content">content</div>
</div>
<div class="container">
    <div class="menu">
        <ul>
            <li>Menu1</li>
            <li>Menu2</li>
            <li>Menu3</li>
            <li>Menu4</li>
        </ul>
    </div> 
    <div class="content">content2</div>
</div>

CSS:

.container{
    padding: 5px 0;
    clear: both;
}
.menu{
   float:left;
    background-color: green;
}
    .menu ul{
        list-style-type: none;
        padding: 0;
        margin:0;
    }
.content{
    background-color: yellow;
    padding-left: 50px;
}

编辑:

在搞砸了 jsFiddle 之后,我想出了This,这里有人似乎有问题吗?本质上它使用显示表和显示表行...

HTML:

<div class="table">
    <div class="row">
        <div class="cell first">
            asdfasdf
        </div>
                <div class="cell second">
            Content 1 
        </div>
    </div>
</div>

<div class="table">
    <div class="row">
        <div class="cell first">
            asdfasdf
        </div>
                <div class="cell second">
            Cotent 2
        </div>
    </div>
</div>

CSS:

.table{
    display table;
    padding-top: 20px;
}

.row{
    display: table-row;
}

.first{
    background-color:green;
}

.second{
        background-color:yellow;
    width: 100%;
}
.cell{
    display:table-cell;
}
4

2 回答 2

1

如果您希望两列具有相同的高度,请尝试一种真正的布局方法:

在这里调整了 JSFiddle。

/* CSS */

.container{
    padding: 5px 0;
    clear: both;
    overflow: hidden;
}

.menu, .content {
    padding-bottom: 999999px;
    margin-bottom: -999999px;
}

.menu{
   float:left;
    background-color: green;
}
    .menu ul{
        list-style-type: none;
        padding: 0;
        margin:0;
    }
.content{
    background-color: yellow;
    padding-left: 50px;
}
于 2013-10-19T18:37:45.837 回答
0

Min-content size....It's a matter of floats the menu and the content and apprppriate widths

NB. Equal height for the menu when the content is a different discussion with various solutions.

JSFiddle Demo (rough as I'd tidy up and use `box-sizing

.container{
    padding: 5px 0;
    clear: both;
     background-color: yellow;
    overflow:hidden;
    margin-bottom:10px;
}
.menu{
   float:left;
    background-color: green;
    width:10%;
}
    .menu ul{
        list-style-type: none;
        padding: 0;
        margin:0;
    }
.content{
 float:left;
    width:80%;
    margin-left:10px;
}
于 2013-10-19T18:26:13.603 回答