gpt4 book ai didi

CSS Flex - 用 div 填充空白区域

转载 作者:行者123 更新时间:2023-11-28 16:34:29 25 4
gpt4 key购买 nike

我离设计师最远,因此我会向其他人寻求视觉设计。我购买了一个模板,设计师在主容器上使用了 min-height: 1000px 属性,以确保背景颜色始终延伸到底部。

我正在尝试更正此问题,因此遇到了以下问题; Make a div fill the height of the remaining screen space - 清楚地标识了新的(ish)css3 flex 属性的使用。但是,似乎我当前的结构可能不允许正确使用它?还是我处理不当?

CSS:

body {
width: 100%;
margin: 0;
padding: 0;
font-family: 'Open Sans',Helvetica, Arial, sans-serif;
color: #666666;
-webkit-font-smoothing: antialiased;
/* Fix for webkit rendering */
-webkit-text-size-adjust: 100%;
font-size-adjust: 100%;
font-weight: 400;
font-size: 13px;
line-height: 1.475;
background-color: #FFF; }

#main {
display: -webkit-flex;
display: flex;
flex-direction: column;
width: 100%;
position: relative;
background: #e8e8e8; }

#content_wrapper {
position: relative;
display: block;
-webkit-flex: 1;
flex: 1;
left: 0px;
margin-left: 230px; }

HTML 结构:

<body>
<header>
<!-- Header Content Here - This is sticky -->
</header>
<div id="main">
<aside id="sidebar_left" class="affix"><!-- Sidebar Content Here - This is sticky --></aside>
<section id="content_wrapper"><!-- Webpage Content Here - This can scroll when necessary. --></section>
</div>
</body>

在内容量合适的页面上,上面看到的是没有问题的。它的工作原理与作者最初的 min-height: 1000px 解决方案相同,但是在内容较短的页面(例如 404 错误等)上,内容大约占页面的 1/3 - 1/2 之前停止。

Flex failing to fill in the gaps!

  • 我没有页脚,也不打算使用页脚。 (以防以后被问到)
  • 我尝试在 html 和 body 标签上使用 height: 100% 但无济于事
  • 我之前曾尝试使用 height:100vh,但意识到它还会增加我的标题区域的高度,因为它存在于视口(viewport)本身中。

我应该如何处理这个问题?Flex 是合适的分辨率吗?

最佳答案

html {
height: 100%; /* Fill all the window */
}
body {
min-height: 100%; /* At least fill all <html> */
display: flex; /* Magic begins */
flex-direction: column; /* Column layout */
}
#main {
flex-grow: 1; /* Grow to fill available space */
}

html {
height: 100%; /* Fill all the window */
}
body {
min-height: 100%; /* At least fill all <html> */
display: flex; /* Magic begins */
flex-direction: column; /* Column layout */
margin: 0;
padding: 0;
}
#main {
flex-grow: 1; /* Grow to fill available space */
display: flex;
background: #e8e8e8;
}
#content_wrapper {
background: yellow;
flex-grow: 1;
}
<header>
Header
</header>
<div id="main">
<aside id="sidebar_left">Aside</aside>
<section id="content_wrapper">Content</section>
</div>

关于CSS Flex - 用 div 填充空白区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30782850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com