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

*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>

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

Bug, padding go overflow in inline-flex+block+flex+block container?

I found strange case. when I use html like that :
<div class="card" style="display:inline-flex; overflow:hidden;">
<div style="display: block; width:10em; height: 5em;">
<div style="display:flex;">
<!-- here -->
<div style="padding-bottom: 10em;"></div>
</div>
</div>
</div>
The div padding-bottom:10em push out others div.card blow the div.card like the padding is some invisible part of the div.card
When I change the internal flex div to block div the bug disapear
It look like the internal flex as it own layout that breach out from the blok and the outer inline-flex
How I prevent that, and make the div with the padding cut out like normal content into overflow hidden element.
It can be I found new bug in chrome flex model ?
Live example :
https://uvzoo.csb.app/
Codesendbox: https://codesandbox.io/s/zen-engelbart-uvzoo
div {
outline: 1px solid pink;
padding: 0.5em;
margin: 0.3em;
}
<div style="display: block; width:30em; height: 40em; padding: 1em;">
<!-- block card -->
<div style="display:inline-flex; overflow:hidden;">
<div style="display: block; width:10em; height: 5em;">
<div style="display:flex;">
<div style="padding-bottom: 10em;"></div>
</div>
</div>
</div>
<!-- end block card -->
<!-- block card -->
<div style="display:inline-flex; overflow:hidden;">
<div style="display: block; width:10em; height: 5em;">
<div style="display:flex;">
<div style="padding-bottom: 10em;"></div>
</div>
</div>
</div>
<!-- end block card -->
<!-- block card -->
<div style="display:inline-flex; overflow:hidden;">
<div style="display: block; width:10em; height: 5em;">
<div style="display:flex;">
<div style="padding-bottom: 10em;"></div>
</div>
</div>
</div>
<!-- end block card -->
<!-- block card -->
<div style="display:inline-flex; overflow:hidden;">
<div style="display: block; width:10em; height: 5em;">
<div style="display:flex;">
<div style="padding-bottom: 10em;"></div>
</div>
</div>
</div>
<!-- end block card -->
<!-- block card -->
<div style="display:inline-flex; overflow:hidden;">
<div style="display: block; width:10em; height: 5em;">
<div style="display:flex;">
<div style="padding-bottom: 10em;"></div>
</div>
</div>
</div>
<!-- end block card -->
</div>
Adding vertical-align:top fixes the issue. I don't know exactly why but it seems there is a complex calculation that is affecting the baseline calculation of each box making it outside and far from the bottom. Since baseline is the default alignment, you are getting this strange result
div {
outline: 1px solid pink;
padding: 0.5em;
}
.box {
display: inline-flex;
vertical-align:top;
overflow: hidden;
}
.box>div {
display: block;
width: 10em;
height: 5em;
}
.box>div>div {
display: flex;
}
.box>div>div>div {
padding-bottom: 10em;
}
<div style="display: block; width:30em; height: 40em; padding: 1em;">
<!-- block card -->
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
</div>
If we add some text we can notice this:
div {
outline: 1px solid pink;
padding: 0.5em;
}
.box {
display: inline-flex;
overflow: hidden;
}
.box>div {
display: block;
width: 10em;
height: 5em;
}
.box>div>div {
display: flex;
}
.box>div>div>div {
padding-bottom: 10em;
}
<div style="display: block; padding: 1em;">
<!-- block card -->
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div> some text here
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
</div> some text here
<div class="box">
<div>
<div>
<div></div>
</div>
</div>
</div>
</div>

Content can be hidden using CSS flexbox with overflow

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.

Metro grid style

I'm trying to achieve something like the following page:
https://undsgn.com/uncode/homepages/blog-metro/
I have tried and was able to come as close as this: https://jsfiddle.net/futu7t1c/
But how can I get those 2 small-thumbs at the bottom to move up?
The order is big, small, small, big, small, small
<div id="blog-posts">
<div class="grid big-thumb">
Title
</div>
<div class="grid small-thumb">
Title
</div>
<div class="grid small-thumb">
Title
</div>
<div class="grid big-thumb">
Title
</div>
<div class="grid small-thumb">
Title
</div>
<div class="grid small-thumb">
Title
</div>
</div>
css
#blog-posts {
-moz-column-count: 1;
-webkit-column-count: 1;
column-count: 1;
-moz-column-gap: 0em;
-webkit-column-gap: 0em;
column-gap: 0em;
}
.grid {
background: #eee;
float: left;
position: relative;
color: #fff;
}
.big-thumb {
width: 50%;
height: 600px;
background: #aeaeae;
}
.small-thumb {
width: 25%;
height: 300px;
background: #353535;
}
To replicate that grid, you can make flex rows that have flex children that are also flex columns holding your images.
.flex {
display: flex;
}
.col {
flex-direction: column;
flex: 0 0 50%;
}
img {
max-width: 100%;
vertical-align: top;
}
<div class="flex row">
<div class="flex col">
<div class="big">
<img src="http://1.bp.blogspot.com/-hNC-oT6f-fY/TeXxO26yjvI/AAAAAAAAAOY/qfkOqdKkBi8/s1600/platon-photographer-putin-man-of-the-year-portrait.jpg">
</div>
<div class="flex row">
<div class="small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
<div class="small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
</div>
</div>
<div class="flex col">
<div class="flex row">
<div class="small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
<div class="small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
</div>
<div class="big">
<img src="http://1.bp.blogspot.com/-hNC-oT6f-fY/TeXxO26yjvI/AAAAAAAAAOY/qfkOqdKkBi8/s1600/platon-photographer-putin-man-of-the-year-portrait.jpg">
</div>
</div>
Well, that's how you'd do it using regular ol' html/css. But since you want to just have a bunch of elements that automatagically lay out like that, use masonry
$('.masonry').masonry({
itemSelector: '.item',
columnWidth: '.small'
});
body {
margin: 0;
}
.item {
float: left;
}
.big {
width: 50%;
}
.small {
width: 25%;
}
img {
width: 100%;
vertical-align: top;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://unpkg.com/masonry-layout#4/dist/masonry.pkgd.min.js"></script>
<div class="masonry">
<div class="item big">
<img src="http://1.bp.blogspot.com/-hNC-oT6f-fY/TeXxO26yjvI/AAAAAAAAAOY/qfkOqdKkBi8/s1600/platon-photographer-putin-man-of-the-year-portrait.jpg">
</div>
<div class="item small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
<div class="item small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
<div class="item big">
<img src="http://1.bp.blogspot.com/-hNC-oT6f-fY/TeXxO26yjvI/AAAAAAAAAOY/qfkOqdKkBi8/s1600/platon-photographer-putin-man-of-the-year-portrait.jpg">
</div>
<div class="item small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
<div class="item small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</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.