我有两个DIV,其中一个具有固定高度,另一个应覆盖页面的其余部分。两者都放在包装DIV中。现在,如果我第二个DIV的内容溢出,我希望DIV滚动(而不是页面)。 我目前的问题是第二个div不与第一个div垂直对齐。我不明白我在这里犯了什么错误,也许你可以发现:
#wrapper, body, html{
height: 100vh;
}
#topbar {
width: 100%;
height: 2em;
border-bottom: $color 0.15em solid;
display: flex;
padding-left: 1em;
div {
line-height: 2em;
padding: 0 0.5em;
cursor: default;
transition: background 0.3s;
&:hover {
background: $accent;
}
}
}
#wrapper {
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
#main {
display: flex;
flex-grow: 1;
overflow: auto;
.main-column {
border-left: $color 0.15em solid;
flex-grow: 1;
}
}
答案 0 :(得分:1)
您可以使用flex-flow
代替flex-direction
并将其应用于.main
。
body {
background: #292929;
font-family: 'Open Sans', Helvetica, Arial, sans-serif;
height: 100%;
font-size: 16px;
color: white;
margin: 0;
}
#wrapper, body, html {
height: 100vh;
}
#topbar {
width: 100%;
height: 2em;
border-bottom: #7CB342 0.15em solid;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
padding-left: 1em;
}
#topbar div {
line-height: 2em;
padding: 0 0.5em;
cursor: default;
-webkit-transition: background 0.3s;
transition: background 0.3s;
}
#topbar div:hover {
background: #5F8339;
}
#wrapper {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-flex-flow: column;
-ms-flex-flow: column;
flex-flow: column;
/* update */
}
#main {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-flow: column;
-ms-flex-flow: column;
flex-flow: column;
/* update */
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
-ms-flex-positive: 1;
flex-grow: 1;
overflow: auto;
}
#main .main-column {
border-left: #7CB342 0.15em solid;
-webkit-box-flex: 1;
-webkit-flex-grow: 1;
-ms-flex-positive: 1;
flex-grow: 1;
}
*, *::before, *::after {
box-sizing: border-box;
padding: 0;
margin: 0;
}
<div id="wrapper">
<div id="topbar">
<div>One</div>
<div>Two</div>
</div>
<div id="main">
<div class="main-column">
e<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br /> e
<br />
</div>
<div class="main-column">
w
</div>
<div class="main-column">
w
</div>
</div>
</div>
答案 1 :(得分:0)
不确定我的问题/请求是否正确,但这是你的意思;
$dark: #292929;
$color: #7CB342;
$accent: #5F8339;
body {
background: $dark;
font-family: 'Open Sans', Helvetica, Arial, sans-serif;
height: 100%;
font-size: 16px;
color: white;
}
#wrapper, body, html{
height: 100vh;
}
#topbar {
width: 100%;
min-height: 2em;
max-height: 2em;
border-bottom: $color 0.15em solid;
display: flex;
padding-left: 1em;
position: fixed;
.bar-item {
line-height: 2em;
padding: 0 0.5em;
cursor: default;
transition: background 0.3s;
&:hover {
background: $accent;
}
}
}
#wrapper {
display: flex;
flex-wrap: wrap;
flex-flow: column;
}
#main {
margin-top: 2em;
display: flex;
flex-grow: 1;
overflow: auto;
position: relative;
.main-column {
max-height: 100%;
border-left: $color 0.15em solid;
flex: 1;
}
}
*, *::before, *::after {
box-sizing: border-box;
padding: 0;
margin: 0;
}
<div id="wrapper">
<div id="topbar">
<div class="bar-item">One</div>
<div class="bar-item">Two</div>
</div>
<div id="main">
<div class="main-column">
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
e<br />
</div>
<div class="main-column">
w
</div>
<div class="main-column">
w
</div>
</div>
</div>