繁体   English   中英

如何使用CSS使列在页眉和页脚之间达到窗口的全高度并防止未包装

[英]How can I make columns full height of window between header and footer with CSS and prevent underwrap

我想使用CSS创建一个简单的HTML布局,其中有一个标题,两列,其中右边的列为固定宽度(例如现在为100px)。 左列有时会生成内容,它不应超出页面底部,但将来可能会...无论如何,我希望两列都可以扩展到页脚...这是我的HTML :

<!DOCTYPE html>
<html>
<head>
  <title>Coming soon...</title>
</head>
<body>
<div class="wrapper">
    <div class="header">
        Header
    </div>
    <div class="content">
         Content Here will be dynamic... sometimes 1 word, sometimes 1000 words! Either way, I want to reach the footer!

    </div>
    <div class="right-menu">
        Here will be a menu... I want this to be the same height as 
      the content DIV
    </div>
    <div class="footer">
        footer
    </div>
</div>
</body>
</html>

这是我的CSS:

.header {
    background-color: Coral ;
    width: 100%;
}

.content {
    background-color: BlanchedAlmond ;
    float:left;
    width:100%;
    margin-right: -100px;

}

.right-menu {
    background-color: BurlyWood ;
    float: right;
    width: 100px;
}

.footer {
    background-color: Coral;
    width: 100%;
    clear: both;
    position: absolute;
    bottom: 0;
}

我对此做了一个JSFiddle,我发现我的内容div似乎也可以在菜单下运行...如何也可以防止这种情况: https : //jsfiddle.net/dwn82s81/

提前谢谢了。 我意识到我已经很久没有编写任何CSS了!

尝试将此更改更改为.content

 .content { background-color: BlanchedAlmond ; float:left; width: 95%; margin-right: -100px; } 

如果您愿意限制IE的兼容性,则可以使用display:flex

请注意,这是一个非常基本的设置。

 html, body { height: 100%; } .wrapper { display: flex; flex-direction: column; height: 100%; } .content-wrapper { flex: 0 0 70%; background: orange; display: flex; } .content { flex: 1 0 auto; } .right-menu { flex: 0 1 150px; } .header, .footer { flex: 0 0 15%; } 
 <div class="wrapper"> <div class="header"> Header </div> <div class="content-wrapper"> <div class="content"> Content Here will be dynamic... sometimes 1 word, sometimes 1000 words! Either way, I want to reach the footer! </div> <div class="right-menu"> Here will be a menu... I want this to be the same height as the content DIV </div> </div> <div class="footer"> footer </div> </div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM