Html 如何将侧边高度与身体高度相匹配

Html 如何将侧边高度与身体高度相匹配,html,css,footer,Html,Css,Footer,我需要将侧边的高度与身体的高度相匹配,而不考虑有多少内容。它给了我图2,我需要图1 我还需要有脚适合内的身体高度位置:绝对确实合适,但会覆盖使主体元素居中的边距:自动。如何对齐div元素 Html代码: 我的css代码如下: body{ width:920px; position:absolute; height:auto; } aside { float:left; width:170px; } footer { float: right;

我需要将侧边的高度与身体的高度相匹配,而不考虑有多少内容。它给了我图2,我需要图1

  • 我还需要有脚适合内的身体高度<代码>位置:绝对确实合适,但会覆盖使主体元素居中的
    边距:自动
    。如何对齐div元素
    Html代码:

    
    



  • 我的css代码如下:

      body{ width:920px;
        position:absolute;
        height:auto; }
    aside { float:left;
        width:170px; }
    
     footer { float: right;
         background: #E7DBD3;
         clear:both; }
    

    您应该能够将数据的顶部和底部值设置在一边。比如:

    aside { 
      position: relative;
      float:left;
      width:170px; 
      top: 0px;
      bottom: 0px;
    }
    

    若要指定侧边元素的高度,而不考虑其内容,请使用position:absolute(位置:绝对)和所需的顶部和底部值

    定位旁侧元素时,请确保其相对于文档体定位,即旁侧元素的祖先应为文档体,而不是任何其他元素。提及顶部和底部值有助于实现旁侧元素的所需高度

    例如,如果页眉的高度为60px,页脚的高度为30px,而旁白应位于左侧,则css代码为

    aside { 
      width: 250px; 
      position: absolute;
      top: 60px;    # to position after the header 
      bottom: 30px; # to end before the footer
      left: 0px;    # to position in the left side..Use right: 0px to position aside in the right side
    }  
    

    尝试设置
    position:absolute
    ?您发布的代码只是部分内容。@Wepex您找到解决方案了吗?@Michel yea我找到了;有许多解决方案:1)将两个对象都放在一边并将其放在正文左边
    aside{float:left}body{float:left}
    2)使用表,即将它们都放在div包装器中,然后
    。将{display:table}放在一边,body{display:table cell}
    3)添加边距和宽度(可能不是最佳解决方案)4)使用引导5)网格6)使用css/javascript/jQuery