css - 如何在不在主 div 上使用 100vh 的情况下让 flex 列菜单拉伸(stretch)到页面的 100%

标签 css flexbox

我在 CMS 上工作,我想要一个完整的 100% 高度。

如何在 wrapper 上没有 100vh 的情况下让我的页面达到 100% 的高度(我猜这是正确的做法)。

body{
	margin: 0;
	font-family: arial;
}

.main-wrapper{
	display: -webkit-box;
    display: -moz-box;
    display: box;
    display: -webkit-flex;
    display: -moz-flex;
    display: -ms-flexbox;
    display: flex;
    flex-direction: row;

    height: 100vh;
    overflow: hidden;

	/*flex-wrap: wrap;*/
}


.main-wrapper div{
}


.sidebar1{
    /*flex-direction: column;*/
	/*flex-wrap: wrap;*/
	/*flex: 1;*/
	/*height: 100%;*/
	/*width: 10px;*/
	/*background-color: #29313c;*/
	background-color: #29313c;
	color: white;
	display: flex;
	flex-direction: column;
	/*height: 100vh;*/
}

.sidebar1 .category{
	flex: 1;
	height: 100%;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #90A4BB;
    text-decoration: none;
    font-weight: bold;
}

.sidebar1 .category:hover{
	color: white;
	background-color: #2E3C54;
}

.sidebar1 .category:not(:last-child){
	border-bottom: 1px solid #90A4BB;
}

.sidebar1 .category div{

}

.sidebar2{
    background-color: #dee3e7;
	flex-wrap: wrap;
    flex-direction: column;
    flex-basis: 330px;
    /*width: 330px;*/

/*	flex: 1;
	flex-wrap: wrap;
    flex-direction: column;	
*/
}


.main-content{
	flex: 5;
	flex-wrap: wrap;
    flex-direction: column;	
	background-color: #fff;
}
<div class="main-wrapper">
	
	<div class="sidebar1">
		
		<a href="#" class="category">
			<div>AAA</div>
		</a>

		<a href="#" class="category">
			<div>BBB</div>
		</a>

		<a href="#" class="category">
			<div>Banana</div>
		</a>

	</div>

	<div class="sidebar2">
		
	</div>

	<div class="main-content">
		
	</div>

</div>

https://jsfiddle.net/nyu1uma1/ (删除高度:100vh)

最佳答案

只要给:

html,body {
    height: 100%;
}

height: 100%;.main-wrapper

.main-wrapper{
    display: -webkit-box;
    display: -moz-box;
    display: box;
    display: -webkit-flex;
    display: -moz-flex;
    display: -ms-flexbox;
    display: flex;
    flex-direction: row;

    height: 100%;
    overflow: hidden;

    /*flex-wrap: wrap;*/
}

Working Fiddle

关于css - 如何在不在主 div 上使用 100vh 的情况下让 flex 列菜单拉伸(stretch)到页面的 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35937716/

相关文章:

html - 当 flexbox 元素以列模式包装时,容器不会增加其宽度

javascript - 在切换时添加和删除类

html - 为什么 flex 元素不缩小过去的内容大小?

javascript - 子域中的 JS Assets 不会在 ff & ie 上加载,但 chrome 一切都很好

html - 如何将包装器应用到这个 flex 盒子并保持响应能力

HTML/CSS 内容在 div 中与 flex 重叠

html - 如何将按钮与输入对齐

html - 图像顶部带有文本的滑动响应图像

html - 隐藏导航栏中除一个之外的所有 <li> 元素

html - 尝试向数据库图像添加线性渐变,我可以在 css 上使用数据库图像吗?