首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >CSS div 100%高度

CSS div 100%高度
EN

Stack Overflow用户
提问于 2013-01-31 23:05:29
回答 5查看 125.1K关注 0票数 31

我正在开发这个website,我希望正确的侧边栏有100%的高度。

body { 
    height: 100%; 
    min-height: 100%;
    position: relative;
}

mydiv { 
    height: 100%; 
    min-height: 100%; 
    position: absolute; 
    top: 0; 
    right: 0; 
    bottom: 0;
    width: 290px;
}

我已经读了很多答案,特别是这个(Prestaul答案):Setting 100% height on an absolutely positioned element when the content expands past the window size

但对我来说,这个技巧不起作用,小提琴的例子也不起作用!

This is the jsfiddle working example.

This is the same code that doesn't work.

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2013-01-31 23:13:58

尝试将正文样式设置为:

body { position:relative;}

这对我很管用

票数 6
EN

Stack Overflow用户

发布于 2013-01-31 23:07:30

也要设置html标记。这样就不需要奇怪的位置技巧了。

html, body {height: 100%}

票数 51
EN

Stack Overflow用户

发布于 2017-11-14 06:47:11

CSS Flexbox旨在简化这些类型的布局的创建。

html {
  height: 100%;
}

body {
  height: 100%;
  display: flex;
}

.Content {
  flex-grow: 1;
}

.Sidebar {
  width: 290px;
  flex-shrink: 0;
}
<div class="Content" style="background:#bed">Content</div>
<div class="Sidebar" style="background:#8cc">Sidebar</div>

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14628838

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档