【问题标题】:building a menu in html with content on the right在 html 中构建一个菜单,内容在右侧
【发布时间】:2013-10-19 18:14:21
【问题描述】:

JsFiddle:Here

所以我遇到了两个问题,我似乎无法找出解决方案。 一:我需要内容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;
}

【问题讨论】:

    标签: html css


    【解决方案1】:

    如果您希望两列的高度相同,请尝试one true layout 方法:

    Adjusted JSFiddle here.

    /* 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;
    }
    

    【讨论】:

      【解决方案2】:

      最小内容大小......这是浮动菜单和内容以及适当宽度的问题

      注意。当内容是不同的讨论与各种解决方案时,菜单的高度相同。

      JSFiddle Demo(粗略我会整理并使用`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;
      }
      

      【讨论】:

      • 你能给我一个解决菜单高度的想法吗?
      • 正如我所说,有很多方法可以做到这一点......其中大多数都是“黑客”。尝试在这里搜索等高的 div...这是一个常见的要求。
      猜你喜欢
      • 2017-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 2017-03-04
      • 1970-01-01
      相关资源
      最近更新 更多