Reputation: 2415
Im trying to set up a simple html layout with a header, a sidebar and a big div for a map. For some reason i see the desired behavior when using Mozilla Firefox, but not in Google Chrome.
So far I have found no answer.
Fiddle: https://jsfiddle.net/hporaozk/4/
HTML:
<div class="wrapper">
<div class="header">HEADER</div>
<div class="content">
<div class="sidebar">
<p>item</p>
<p>item</p>
<p>item</p>
<p>item</p>
<p>item</p>
<p>item</p>
<p>item</p>
<p>item</p>
<p>item</p>
<p>item</p>
<p>item</p>
<p>item</p>
<p>item</p>
<p>item</p>
<p>item</p>
<p>item</p>
</div>
<div class="map-container">
<div class="map">actual map</div>
</div>
</div>
</div>
css:
.wrapper{
height: 100vh;
width: 100%;
display: flex;
flex-direction: column;
}
.header{
flex: 0 0 50px;
width: 100%;
background-color: #ff0000;
}
.content{
flex: 1;
width: 100%;
display: flex;
flex-direction: row;
}
.sidebar{
background-color: #00ff00;
flex: 0 0 240px;
height: 100%;
overflow-y: scroll;
}
.map-container{
flex: 1;
height: 100%;
position: relative;
}
.map{
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: #0000ff;
}
Upvotes: 2
Views: 4788
Reputation: 44098
Here you go: DEMO
The most important part is to set your flex items (.map-container
and .sidebar
) to flex-basis: 50%
which is in the flex shorthand flex: 0 1 50%
You can adjust those accordingly.
.wrapper {
height: 100vh;
width: 100%;
display: flex;
display: -webkit-flex;
flex-direction: column;
-webkit-flex-direction: column;
}
.header {
flex: 0 0 50px;
width: 100%;
background-color: #ff0000;
}
.content {
flex: 1 0 100%;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-justify-content: space-around;
justify-content: space-around;
-webkit-align-content: flex-start;
align-content: flex-start;
-webkit-align-items: space-around;
align-items: space-around;
}
.sidebar {
background-color: #00ff00;
-webkit-flex: 0 1 50%;
flex: 0 1 50%;
overflow-y: scroll;
}
.map-container {
position: relative;
-webkit-flex: 0 1 50%;
flex: 0 1 50%;
}
.map {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
background-color: #0000ff;
}
Upvotes: 2
Reputation: 1
First of all, I hope you always use prefixes if you're working with flex-box, otherwise you will have a lot of funky business to work with.
In this case you problem is easy to solve:
Just set a height on .content!
.content{
flex: 1;
width: 100%;
display: flex;
flex-direction: row;
height: 100%; // add this
}
Upvotes: 0