Content can be hidden using CSS flexbox with overflow - html

I'm new to using flex boxes in CSS. But this seems very nice for alignments and free space distribution between components!
Today I have a problem I don't manage to solve. Thanks in advance for your help.
Here is a codepen to illustrate the problem quickly :
https://codepen.io/anon/pen/BYdzqR
#example1 .wrapper, #example1bis .wrapper{
justify-content: space-between;
}
#example2 .wrapper, #example2bis .wrapper{
justify-content: space-evenly;
}
#example3 .wrapper, #example3bis .wrapper{
justify-content: space-around;
}
#example4 .wrapper, #example4bis .wrapper{
justify-content: center;
}
#example4 .content .group, #example4bis .content .group {
margin: auto;
}
#example1, #example2, #example3, #example4{
height: 600px;
}
#example1bis, #example2bis, #example3bis, #example4bis{
height: 300px;
}
.root{
/* background: lightblue; */
margin-bottom: 20px;
display: flex;
}
.box {
width: 300px;
height: 300px;
border: 1px solid gray;
text-align: center;
margin: 0 20px;
flex: 0 0 auto;
}
.wrapper {
display: flex;
flex-flow: column nowrap;
height: 100%;
}
/* ----------------------------- */
/* Top */
/* ----------------------------- */
.top {
padding: 20px 0;
overflow: hidden;
flex: 0 0 auto;
border-bottom: 1px solid lightgray;
}
/* ----------------------------- */
/* Content */
/* ----------------------------- */
.content {
padding: 10px;
overflow-y: auto;
flex: 1 1 auto;
}
.content .group {
flex: 0 0 auto;
background: yellow;
width: 100%;
}
.content h2 {
margin: 0;
padding: 0;
color: red
}
/* ----------------------------- */
/* Bottom */
/* ----------------------------- */
.bottom {
text-align: center;
width: 100%;
padding: 20px 0;
overflow: hidden;
flex: 0 0 auto;
border-top: 1px solid lightgray;
}
<h1>Reference : without overflow</h1>
<p>Different kind of free space allocation. What I would like is something like #2 ("justify-content: space-evenly"). Eventually #3 ("space-around") or #4 ("center", with "margin: auto" on items)</p>
<div class="root">
<div id="example1" class="box">
<div class="wrapper">
<div class="top">
#1 : space-between
</div>
<div class="content wrapper">
<div class="group">
<h2>Section 1</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 2</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 3</h2>
<p>blah</p>
</div>
</div>
<div class="bottom">
footer
</div>
</div>
</div>
<div id="example2" class="box">
<div class="wrapper">
<div class="top">
#2 : space-evenly
</div>
<div class="content wrapper">
<div class="group">
<h2>Section 1</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 2</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 3</h2>
<p>blah</p>
</div>
</div>
<div class="bottom">
footer
</div>
</div>
</div>
<div id="example3" class="box">
<div class="wrapper">
<div class="top">
#3 : space-around
</div>
<div class="content wrapper">
<div class="group">
<h2>Section 1</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 2</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 3</h2>
<p>blah</p>
</div>
</div>
<div class="bottom">
footer
</div>
</div>
</div>
<div id="example4" class="box">
<div class="wrapper">
<div class="top">
#4 : center
</div>
<div class="content wrapper">
<div class="group">
<h2>Section 1</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 2</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 3</h2>
<p>blah</p>
</div>
</div>
<div class="bottom">
footer
</div>
</div>
</div>
</div>
<h1>Problem : with overflow</h1>
<p>The problem is when there is not enough free space to display all the content. "overflow-y: auto" should allow to scroll to see all the content, but this is not the case with #2, #3 and #4... ("Section 1" title hidden)</p>
<div class="root">
<div id="example1bis" class="box">
<div class="wrapper">
<div class="top">
#1bis : space-between = OK
</div>
<div class="content wrapper">
<div class="group">
<h2>Section 1</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 2</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 3</h2>
<p>blah</p>
</div>
</div>
<div class="bottom">
footer
</div>
</div>
</div>
<div id="example2bis" class="box">
<div class="wrapper">
<div class="top">
#2bis : space-evenly = KO
</div>
<div class="content wrapper">
<div class="group">
<h2>Section 1</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 2</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 3</h2>
<p>blah</p>
</div>
</div>
<div class="bottom">
footer
</div>
</div>
</div>
<div id="example3bis" class="box">
<div class="wrapper">
<div class="top">
#3bis : space-around
</div>
<div class="content wrapper">
<div class="group">
<h2>Section 1</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 2</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 3</h2>
<p>blah</p>
</div>
</div>
<div class="bottom">
footer
</div>
</div>
</div>
<div id="example4bis" class="box">
<div class="wrapper">
<div class="top">
#4bis : center
</div>
<div class="content wrapper">
<div class="group">
<h2>Section 1</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 2</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 3</h2>
<p>blah</p>
</div>
</div>
<div class="bottom">
footer
</div>
</div>
</div>
</div>
Explanation :
I have some "boxes" (in fact they are modals) with a header, a footer, and some content between. I would like the header and footer parts always visible, and the content scroll if too big to display all.
In the content part, I have several "sections" (groups of other items).
I would like these "groups" to be equidistant from each other (ie: free space between grows when it can. I saw the flex container property justify-content: space-evenly that is exactly what I want.
This is fine when I have to much space to display my content. I takes all the available space with "harmony".
The problem is when I have many content and that it cannot be displayed. So all the "groups" will be sticked. fine. I put my content an overflow-y: auto so it will scroll in that case.
But with justify-content: space-evenly, I can't access the top of my content even when the scroll is at the top. It is OUTSIDE the content wrapper...
Same problem with justify-content: space-around or justify-content: center + margin: auto on the flex items.
The only working solution is justify-content: space-between, but unfortunately this is not the behaviour I want...
What can I do to achieve this and have access to all my content if there is a scroll ??
Thanks.

space-evenly is a new property and won't work cross browsers (read more at the end).
As of today, you could use auto margin, where in this case all group items get a bottom auto margin, and the first also get a top auto margin.
That will generate the output you asked for.
Updated codepen
Stack snippet
body {
margin: 0;
}
.wrapper {
height: 100vh;
display: flex;
flex-flow: column nowrap;
}
.content {
padding: 10px;
overflow: auto;
flex: 1 1 auto;
display: flex;
flex-flow: column nowrap;
}
.content .group {
margin-bottom: auto;
flex: 0 0 auto;
background: yellow;
}
.content .group:first-child {
margin-top: auto;
}
.content h2 {
margin: 0;
padding: 0;
}
.top, .bottom {
text-align: center;
padding: 20px 0;
overflow: hidden;
flex: 0 0 auto;
border: 1px solid lightgray;
}
<div class="wrapper">
<div class="top">
auto margin
</div>
<div class="content">
<div class="group">
<h2>Section 1</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 2</h2>
<p>blah</p>
</div>
<div class="group">
<h2>Section 3</h2>
<p>blah</p>
</div>
</div>
<div class="bottom">
footer
</div>
</div>
Even with space-evenly one also need to add yet another new feature, a new keyword called safe, though it is still a working draft, and not many (if any) browsers support it yet.
And the reason is, when using e.g. justify-content, the overflow, in this case when using column direction, will be at both the top and bottom of the flex container.

Related

how to position elements one to left and other right one below the other- CSS

I am trying to position the following elements one below the other , but one to the left and other to the right:
my code:
here is the fiddle: https://jsfiddle.net/ak9hxfpt/2/
I want to position the test2 to the right of the test1 div, but it should appear below the test1 div
What I want to achieve is something like: https://jsfiddle.net/ak9hxfpt/3/
however this works only for one div, if I try float: right for all the divs I have this is what I get which is not working out for me:
https://jsfiddle.net/ak9hxfpt/4/
the every "remove link" content should appear below every "some content".
any ideas on how this can be achieved
.test2 {
margin-bottom: 30px;
}
.test1 {
border: 1px solid #000;
margin-bottom: 10px;
width: 93%;
}
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
just add some margin-left
.test2 {
margin-bottom: 30px;
margin-left:80%;
}
.test1 {
border: 1px solid #000;
margin-bottom: 10px;
width: 93%;
}
<div class="test2">
remove link
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
or
.test2 {
margin-bottom: 30px;
width:93%;
text-align:right;
}
.test1 {
border: 1px solid #000;
margin-bottom: 10px;
width: 93%;
}
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
I would try nesting your code in a container and use display: flex; with flex-direction: column;
.test2 {
float: right;
}
.test1 {
border: 1px solid #000;
margin-bottom: 10px;
width: 93%;
}
.container {
display: flex;
flex-direction: column;
}
<div class="container">
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
</div>
Another option would be to set display: flex; on test right a flex-direction: row; then you can can set test2 to width: 7%; while test still takes up 93%. Finally, you can space them by adding gap Check the snippet below.
.test2 {
width: 7%;
}
.test1 {
border: 1px solid #000;
margin-bottom: 10px;
width: 93%;
}
.test {
display: flex;
flex-direction: row;
width: 100%;
gap: 10px;
}
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
<div class="test">
<div class="test1">
some content
</div>
<div class="test2">
remove link
</div>
</div>
Just add display: flex; justify-content: flex-end to your test2 class and it will work.enter image description here

Control middle space between 2 flex items in a row

How can I control the middle space between 2 flex items in a row? My goal is to minimize the middle space between the items.
In other words, I want to right and center align the columns, while keeping the text centered.
I would also like to be able to control the middle gutter. Also, maybe be able to say that the middle gutter should be some fixed pixel quantity like 20px.
This doesn't work because there is too much space in the middle
.row {
display: flex;
}
.column {
border: 1px solid #ccc;
width: 50%;
}
h2 {
text-align: center;
}
<div class="row">
<div class="column first">
<h2>Centered</h2>
<h2>Text</h2>
</div>
<div class="column second">
<h2>Centered</h2>
<h2>Text</h2>
</div>
</div>
This don't work because the text in not centered
.row {
display: flex;
}
.column {
border: 1px solid #ccc;
width: 50%;
}
h2 {
text-align: center;
}
.first h2 {
text-align: right;
}
.second h2 {
text-align: left;
}
<div class="row">
<div class="column first">
<h2>Centered</h2>
<h2>Text</h2>
</div>
<div class="column second">
<h2>Centered</h2>
<h2>Text</h2>
</div>
</div>
If you want your elements to have a particular proportion in relation to each other or to the whole (i.e: 50%), flexbox is not even the best solution (although it can be crow-bared to fulfill the requirement).
A simple display: inline-block; width: 50%; box-sizing: border-box on the children will do.
Flexbox was designed to allow fluid distribution of positive or negative space.
As in, after the browser determines how much space the children need and how much they have available, by comparing the two it deals with two cases:
positive space: when parent > sum of children, redistribute the space to each child, proportionally with their respective flex-grow values (until the space is filled) or, if no children have positive flex-grow values, distribute the space in between the children
negative space: if parent < sum of children, shrink each child proportionally with their flex-shrink values.
You have a case of positive space, where the children do not have flex-grow, so the space can be redistributed in between them. You have three options:
justify-content: space-between
justify-content: space-around
justify-content: space-evenly
Notice how the spaces are equally distributed in each case. That's why it's called flexbox, that's what it was designed for and, if you want, that's its superpower.
When you set width: 50% you kind of take all of that away:
.row {
display: flex;
width: 100%;
}
.row>* {
border: 1px solid #ccc;
text-align: center;
}
.one {
justify-content: space-between;
}
.two {
justify-content: space-around;
}
.three {
justify-content: space-evenly;
}
.grow>* {
flex-grow: 1;
margin: 1rem;
}
<code>justify-content: space-between</code>
<div class="row one">
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
</div>
<code>justify-content: space-between (unequal)</code>
<div class="row one">
<div>
<h2>A bigger element here</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
</div>
<hr>
<code>justify-content: space-around;</code>
<div class="row two">
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
</div>
<code>justify-content: space-around; (unequal)</code>
<div class="row two">
<div>
<h2>A bigger element here</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
</div>
<hr>
<code>justify-content: space-evenly;</code>
<div class="row three">
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
</div>
<code>justify-content: space-evenly; (unequal)</code>
<div class="row three">
<div>
<h2>A bigger element here</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
</div>
<hr>
<code>> flex-grow: 1;</code>
<div class="row grow">
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
</div>
<hr>
<code>> flex-grow: 1; (unequal elements)</code>
<div class="row grow">
<div>
<h2>A bigger element here</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
</div>
A more detailed explanation on how flexbox works can be found here.
The official spec is here.
Considering your question, there's a big chance justify-content: space-evenly does what you want, but I can't be sure, as your question is not extremely clear.
Important note: You can always use margin and padding on your elements, which will push them around accordingly. Also note margin: auto on flexbox children will steal the positive space from flexbox and will redistribute it equally between all the margin:autos present in parent space (and will make it look like flexbox doesn't work properly; it actually does, but there's nothing left to redistribute).
If you want to have a particular distance in between your elements and the entire composition should be centered in the available space, you could center a single item in the available space and inside that item you could place the items, so that the entire thing is centered regardless of the fact the items are unequal.
Example:
.row {
display: flex;
justify-content: center;
}
.row > * {
margin: 0 auto;
display: flex;
}
.row>*>* {
border: 1px solid #ccc;
text-align: center;
margin: 1rem;
}
<div class="row">
<div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
</div>
</div>
<hr>
<div class="row">
<div>
<div>
<h2>Much more text here</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
</div>
</div>
<hr>
<div class="row">
<div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Much more text here</h2>
<p>Text</p>
</div>
</div>
</div>
But, again, that's not something you need flexbox for.
The exact same can be achieved using a simple parent > child structure, where parent has display: block; text-align: center; and children have display: inline-block;
.row {
text-align: center;
}
.row>* {
border: 1px solid #ccc;
text-align: center;
margin: 1rem;
display: inline-block;
}
<div class="row">
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
</div>
<hr>
<div class="row">
<div>
<h2>Much more text here</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
</div>
<hr>
<div class="row">
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Centered</h2>
<p>Text</p>
</div>
<div>
<h2>Much more text here</h2>
<p>Text</p>
</div>
</div>
Notice the absence of the extra wrapper in markup.
Why not simply use a CSS grid for the task? It offers the grid-column-gap property which does exactly what you need:
.row {
display: grid;
grid-template-columns: 1fr 1fr;
grid-column-gap: 10px;
}
.column {
border: 1px solid #ccc;
}
h2 {
text-align: center;
}
<div class="row">
<div class="column">
<h2>Centered<br />Text</h2>
</div>
<div class="column">
<h2>Centered<br />Text</h2>
</div>
</div>
Try doing this
.column:not(:last-child){
margin-left: 20px;
}

Page to cut off at window with html & body display: hidden

*Note: based on the answers by #aavrug and #kukkuz, I have restructured my question so that it fully conveys what I am trying to ask.
I have a page layout which has a top nav-bar and a side nav-bar. It also has a main part in which the data is shown. As I only want the main part to scroll, I set html, body { overflow: hidden; } and .main { overflow-y: auto; }. I have further transformed the page into a flex-box after kukkuz's answer. This is what I have so far:
html,
body,
.container {
overflow: hidden;
height: 100%;
margin: 0;
}
.container {
display: flex;
}
.column {
flex-flow: column;
}
div {
border: 1px dotted green;
margin: 2px;
}
.top,
.side {
float: left;
display: flex;
}
.side span {
align-self: flex-end;
}
.top span{
margin-left: auto;
}
.top {
background-color: steelblue;
height: 128px;
width: 100%;
/* This might be code-smell as a div already is a block element, but removing it doesn't make the layout work */
}
.side {
background-color: gold;
width: 128px;
height: 100%;
}
.main {
height: 100%;
overflow-x: hidden;
overflow-y: auto;
flex: 1;
}
.big {
height: 32px;
background-color: #369;
}
.small {
height: 16px;
background-color: #a12;
}
<div class="container column">
<div class="top"><span>Where is the green border at the side??? ></span></div>
<div class="container">
<div class="side"><span>Where is the green border at the bottom??? \/<span></div>
<div class="main">
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
</div>
</div>
</div>
It seems to work as planned (what I was running into earlier is that the .main - .window in the old question - was expanding below the page and thus you could not scroll the entire page length); however, if you look at the bottom and right side of the resulting page, you will see that the borders which are supposed to be there, are not there, giving to the idea that the page does not actually cut off at the bottom of the window (on the right side, the ">" I put even disappears into the side of the window a bit).
Here's the jsfiddle as well.
Thus, my question is, how would one properly use html, body { overflow: hidden; } while still containing the laid out elements so that they are fully visible.
In my example above I use html, body { height: 100%; } I have also tried height: 100vh; but that did not work.
P.S. If it seems that I am asking a separate question to the un-revised question, I am not. This is still the same problem, just now I have fully provided all elements to it. Tku.
You can do this using a flexbox:
First put height: 100% on the body and remove the default margins.
Wrap your window into a flexbox like this:
<div class="window-wrapper">
<div class="window">
<!-- more code here -->
</div>
</div>
.window-wrapper{
display: flex;
flex-direction: column;
height: 100%;
}
And there you go. Let me know your feedback on this. Thanks!
html,
body {
overflow: hidden;
margin: 0;
height: 100%;
}
.window-wrapper {
display: flex;
flex-direction: column;
height: 100%;
}
.window {
margin-top: 128px;
margin-left: 128px;
overflow-y: auto;
}
.big {
height: 32px;
background-color: #369;
}
.small {
height: 16px;
background-color: #a12;
}
<div class="window-wrapper">
<div class="window">
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
</div>
</div>
Updated answer:
Remove the floats
Wrap the window with a div with styles like this:
.window-wrapper {
overflow-x: hidden;
overflow-y: auto;
flex: 1;
}
.window {
height: 100%;
}
The container that wraps the sidebar and the content should have flex: 1 and should not have height: 100%. So added this style:
.container-inner {
display: flex;
margin: 0;
flex: 1;
}
Removed height: 100% from the side too.
To finish things up, added box-sizing: border-box to all elements to prevent the overflows.
* {
box-sizing: border-box;
}
html,
body,
.container {
overflow: hidden;
height: 100%;
margin: 0;
}
.container {
display: flex;
}
.container-inner {
display: flex;
margin: 0;
flex: 1;
}
.column {
flex-flow: column;
}
div {
border: 1px dotted red;
margin: 2px;
}
.top {
background-color: steelblue;
height: 128px;
width: 100%;
/* This might be code-smell as a div already is a block element, but removing it doesn't make the layout work */
}
.side {
background-color: gold;
width: 128px;
}
.window-wrapper {
overflow-x: hidden;
overflow-y: auto;
flex: 1;
}
.window {
height: 100%;
}
.big {
height: 32px;
background-color: #369;
}
.small {
height: 16px;
background-color: #a12;
}
<div class="container column">
<div class="top"></div>
<div class="container-inner">
<div class="side"></div>
<div class="window-wrapper">
<div class="window">
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
</div>
</div>
</div>
</div>
A small modificaton required in your div
html,
body {
overflow: hidden;
}
.window {
margin: 64px;
overflow-y: auto;
height: 100px;
}
.big {
height: 32px;
background-color: #369;
}
.small {
height: 16px;
background-color: #a12;
}
<div class="window">
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
<div class="big">
I'm big
</div>
<div class="small">
I'm small
</div>
</div>

Bootstrap 4 flexbox content 100% height

I Have some problems with Bootstrap 4.
I Have activated flexbox and i want content in column to be 100% height.
This is the structure:
<div class="row">
<div class="col-md-6 col-xs-12">
<div class="content">
</div>
</div>
</div>
This is the result:
Flexbox
How can the gray background be 100% height? i tried with height: 100%. But the container will be 100% height of the page and not of the column. I also tried to set parent to relative and child to absolute. Doesn't worked.
Background color is set on content.
Codeexample:
http://jsfiddle.net/KjGZw/339/
You need to make the .col divs flex-containers with display:flex and apply flex-direction:column to those.
Then set the .content divs to flex:1
.row {
height: auto;
display: flex;
flex-wrap: wrap;
}
.col {
padding: 15px;
flex: 1 1 25%;
display: flex;
flex-direction: column;
}
.content {
background: purple;
color: white;
padding: 15px;
flex: 1;
}
*,
:after,
:before {
box-sizing: inherit;
}
<div class="row">
<div class="col">
<div class="content">
Test
<br />Test
<br />Test
<br />Test
<br />Test
<br />
</div>
</div>
<div class="col">
<div class="content">
Test
</div>
</div>
<div class="col">
<div class="content">
Test
</div>
</div>
<div class="col">
<div class="content">
Test
</div>
</div>
<div class="col">
<div class="content">
Test
<br>Test
<br>Test
<br>Test
<br>
</div>
</div>
<div class="col">
<div class="content">
Test
</div>
</div>
</div>

Display, generated div's horizontally within a container with scrollbar

I am trying to display dynamic generated div's horizontally with scroll bar. There can be n number of div's.
Below is my Code:
HTML (index.html)
<div style="width:100%;float:left;" id="old">
<div>
<h1>First Div</h1>
<div id="R1">
<h1>First Div Internal</h1>
<a id="R1_index" class="close_page" href="javascript:void(0)">Close</a>
</div>
</div>
<div>
<h1>Second Div</h1>
<div id="R2">
<h1>Second Div Internal</h1>
<a id="R2_index" class="close_page" href="javascript:void(0)">Close</a>
</div>
</div>
</div>
I follow this link for solution.
But when dynamic div's load, structure looked messed up.
Here is the messy look:
HTML (index.html)
<div style="width:100%;float:left;" id="old">
<div id="items">Missing Internal Content</div>
<div id="items">Missing Internal Content</div>
</div>
Please help me guys.
i imagin the problem is that the div's in the container (id="old" in your example) are not next to each other, but instead beneath.
if that is your problem, you add the following styles to your container:
#old {
overflow: auto;
white-space: nowrap;
}
and make the childern-divs inline-block elements:
#old > div {
display: inline-block;
}
then it should work as expected. see the working solution:
* {
padding: 0;
margin:0;
}
#container {
width: 300px;
height: 100px;
overflow: auto;
white-space: nowrap;
}
.element {
display: inline-block;
}
.box {
width: 100px;
height: 100px;
background: lightgrey;
}
<div id="container">
<div class="element">
<div class="box">
<h1>1</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>2</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>3</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>4</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>5</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>6</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>7</h1>
</div>
</div>
<div class="element">
<div class="box">
<h1>8</h1>
</div>
</div>
</div>
otherwise please provide a better example/description of what the problem exactly is.