HTML / CSS what is optimal to get following layout construction - html

I am trying to achieve the following layout through HTML and css:
In this layout you have a red upper div, which is 100% the window width and has the height of it's containing elements
Beneath that you have a green div, containing menu items next to each other, which is 100% the window width as well and has a height that makes it fill the rest of the window.
Next to the green div there is a yellow div which momentarily has a width of 0%.
When clicking an item in the green div makes the green div shift right with the width being the width of the widest menu item and the height that makes it fill the rest of the window.
The yellow div then opens next to the green div and it's width covers the rest of the window. Same for the height, this should make it fill the rest of the window. It contains an iframe that displays the clicked menu item and should cover the yellow div entirely.
I have no problem getting the first layout, however when switching to the 2nd I can't seem to get the green and yellow divs' height right.
Here's what I've got:
<div id="Dashboard_CAClientDIV">
Red div
</div>
<div id="Dashboard_MenuDIV">
Green div
<div class="Dashboard_Tile">
Item 1
</div>
<div class="Dashboard_Tile">
Item 2
</div>
<div class="Dashboard_Tile">
Item 3
</div>
<div class="Dashboard_Tile">
Item 4
</div>
<div class="Dashboard_Tile">
Item 5
</div>
</div>
<div id="Dashboard_FrameDIV">
<iframe id="Yellow Div" src="" width="100%" height="100%">
</div>
Going to the 2nd layout adds "_Exp" to Dashboard_MenuDIV and Dashboard_FrameDIV, here's the css I've got:
html, body, #frmDashboard {
/* any div up to fullscreen-cont must have this
in this case html and body */
height:100%;
min-height:100%;
max-height: 100%;
}
body, div {
/*overflow: hidden;*/
margin: 0px;
}
.Dashboard_Tile {
display:inline-block;
}
#Dashboard_MenuDIV_Exp, #Dashboard_FrameDIV_Exp {
min-height: 100%;
height: 100%;
max-height: 100%;
display: inline-block;
}
#Dashboard_MenuDIV_Exp .Dashboard_Tile {
min-width: 100%;
width: 100%;
max-width: 100%;
margin-top: 1px;
}
#Dashboard_CAClientDIV {
min-width:100%;
width:100%;
max-width:100%;
}
#Dashboard_MenuDIV {
min-width:100%;
width:100%;
max-width:100%;
}
#Dashboard_MenuDIV_Exp {
min-width:20%;
width:20%;
max-width:20%;
float: left;
}
#Dashboard_FrameDIV {
min-width:0%;
width:0%;
max-width:0%;
}
#Dashboard_FrameDIV_Exp {
min-width:75%;
width:75%;
max-width:75%;
float: left;
}
Thanks in advance

Use the new CSS3 flex layout: http://css-tricks.com/snippets/css/a-guide-to-flexbox/:
Working fiddle: http://jsfiddle.net/5UXR9/2/
HTML:
<div id="Dashboard_CAClientDIV">Red div</div>
<div id="Dashboard_Wrapper_MenuDIV_and__FrameDIV">
<div id="Dashboard_MenuDIV">
Green div
<div class="Dashboard_Tile small">Item 1</div>
<div class="Dashboard_Tile small">Item 2</div>
<div class="Dashboard_Tile very-large">Item 3</div>
<div class="Dashboard_Tile small">Item 4</div>
<div class="Dashboard_Tile large">Item 5</div>
</div>
<div id="Dashboard_FrameDIV">
<iframe id="Yellow Div" src="" width="100%" height="100%"></iframe>
</div>
</div>
CSS:
body, html {
height: 100%;
}
#Dashboard_CAClientDIV {
background-color: red;
height: 40px;
width: 100%;
}
#Dashboard_Wrapper_MenuDIV_and__FrameDIV {
width: 100%;
height: 100%;
display: flex;
}
#Dashboard_MenuDIV {
background-color: green
}
#Dashboard_MenuDIV .Dashboard_Tile {
background-color: blue;
height: 50px;
margin-bottom: 5px;
}
#Dashboard_MenuDIV .Dashboard_Tile.small {
width: 100px;
}
#Dashboard_MenuDIV .Dashboard_Tile.large {
width: 200px;
}
#Dashboard_MenuDIV .Dashboard_Tile.very-large {
width: 300px;
}
#Dashboard_FrameDIV {
background-color: yellow;
flex: auto;
}
#Dashboard_FrameDIV iframe {
border: none;
}

Well, a CSS3 solution has already been given, but if you want a more primitive approach (CSS2), you can style your layout with display:table properties. Here's an example similar to your situation:
http://jsfiddle.net/S562t/
HTML:
<div class="stage">
<div class="row-top">
<div class="top">red</div>
</div>
<div class="row-bottom">
<div class="left">
<div class="title">Title 1</div>
<div class="title">Title 2334234234</div>
<div class="title">Title 3</div>
<div class="title">Title 4</div>
</div>
<div class="right">
<iframe src="" frameborder="0"></iframe>
</div>
</div>
</div>
CSS:
.stage
{
overflow: hidden;
display: table;
position: absolute;
width: 100%;
height: 100%;
top:0;
left:0;
}
.row-top
{
display: table-row;
position: relative;
height: 30px;
}
.row-bottom
{
display: table-row;
position: relative;
}
.top
{
background-color: red;
display: table-cell;
position: absolute;
width: 100%;
height: 30px;
}
.left
{
background-color: green;
display: table-cell;
}
.right
{
background-color: yellow;
display: table-cell;
}
iframe
{
width: 100%;
height: 100%;
}
http://jsfiddle.net/S562t/

Related

How to restrict the dynamic height of the tallest descendant in a flexbox layout?

I have a flexbox wrapper which has two descendants. They both have dynamic height. The second block could be higher than the first one, and I would like to limit the height of the second block to the same as the height of the first one.
.wrapper {
border: 1px solid black;
display: flex;
width: 400px;
margin-bottom: 100px;
}
.left {
background-color: blue;
height: 100px;
width: 200px;
}
.right {
width: 200px;
}
.first {
height: 70px;
background-color: yellow;
}
.second {
height: 70px;
background-color: green;
}
/*desired result */
.fixed-height {
height: 100px;
}
.overflow-value {
overflow: auto;
}
<div class="wrapper">
<div class="left"></div>
<div class="right">
<div class="first"></div>
<div class="second"></div>
</div>
</div>
<div class="wrapper fixed-height">
<div class="left"></div>
<div class="right overflow-value">
<div class="first"></div>
<div class="second"></div>
</div>
</div>
In the provided example, there two wrappers: the first one is the current wrapper, where the wrapper has the height of the tallest child. And the second one is the desired result (I added height to the wrapper, but I couldn't do it in real application)
CodePen Example
If you insist on using flexbox then there is a way to force the container to just take the height of specific child into account - this can be done by forcing the contents of the second item out of layout context with position: absolute. Unfortunately, this requires adding another wrapper inside the .right element. In addition, having the items positioned absolutely inside the second item will mean that the width of the contents will not be propagated to the .right element, but since your example has an explicit width set, then it works in this case. The code with those modifications is below:
.wrapper {
border: 1px solid black;
display: flex;
width: 400px;
margin-bottom: 100px;
}
.left {
background-color: blue;
height: 100px;
width: 200px;
}
.right {
width: 200px;
position: relative;
overflow: auto;
}
.first {
height: 70px;
background-color: yellow;
}
.second {
height: 70px;
background-color: green;
}
.right-wrapper {
position: absolute;
width: 100%;
}
<div class="wrapper">
<div class="left"></div>
<div class="right">
<div class="right-wrapper">
<div class="first"></div>
<div class="second"></div>
</div>
</div>
</div>

adding inline-block divs moves parent to the bottom of the screen

I have 2 divs (.showcase, .highlight) nested inside an element with position: relative:
I would like to have a margin on the left of the .contentContainer for the navigation menu (23.79%). Then I would like 2 divs inside the contentContainer div that extend the whole height of the screen, regardless of their content. Then I would like to add content inside those two divs.
<div id="App">
<div data-reactroot="">
<div class="navbarContainer">
</div>
<div class="contentContainer">
<div class="showcase">
<div class="thumb"></div>
<div class="thumb"></div>
<div class="thumb"></div>
<div class="thumb"></div>
</div>
<div class="highlight"></div>
</div>
</div>
</div>
Now when I add more divs into my showcase div, the .showcase div gets moved to the bottom of the screen (so only the 100px of the .thumb divs are visible.). I can't figure out what I am doing wrong.
Stylesheet:
#App {
background-color: #fff;
color: $fontC2;
font-family: 'Roboto';
min-height: 100vh;
min-width: 320px;
position: relative;
}
.contentContainer {
margin-left: 23.79%;
width: 76.21%;
height: 100vh;
.showcase {
width: 61%;
height: 100vh;
display: inline-block;
background-color: red;
top: 0;
.thumb {
width: 20%;
height: 100px;
background-color: $primaryC3;
display: inline-block;
}
}
.highlight {
width: 39%;
background-color: $primaryC2;
height: 100vh;
display: inline-block;
}
}
Fiddle here:
https://jsfiddle.net/2tz9940v/

How do I make a div take the remaining height of a parent?

JsFiddle Demo
I have 2 divs in a container (actually I tagged the first as h1) and I'd like the 2nd div to take the remaining space of it's parent div. Doing height:100% makes it use 100% of its parent height causing it to be larger then the parent because of the other div. In the demo you can see the blue pass the grey.
How do I tell it to use the remaining height? The HTML may change but try not to go crazy
HTML:
<div class="outer_box">
<div class="container">
<h1>Title</h1>
<div class="box">Box</div>
</div>
<div class="container">
<h1>Title</h1>
<div class="box2">Box</div>
</div>
</div>
CSS:
.outer_box {
height: 500px;
}
.container {
width: 30%;
height: 100%;
background-color: grey;
float:left
}
.box {
background-color: blue;
height: 100%;
}
.box2 {
background-color: green;
}
You could do the CSS table layout, and set the box to height:100% to push the title to its minimal height.
http://jsfiddle.net/0w7pqeo6/3/
.outer_box {
height: 300px;
}
.container {
width: 30%;
height: 100%;
background-color: grey;
float: left;
display: table;
}
.container h1, .container > div {
display: table-row;
}
.box {
background-color: blue;
height: 100%;
}
.box2 {
background-color: green;
height: 100%;
}
<div class="outer_box">
<div class="container">
<h1>Title</h1>
<div class="box">Box</div>
</div>
<div class="container">
<h1>Title</h1>
<div class="box2">Box</div>
</div>
</div>
http://jsfiddle.net/utsavoza/9v0dfv39/
HTML part
Title
<div class="box">Box</div>
</div>
<div class="container">
<h1>Title</h1>
<div class="box2">Box</div>
</div>
CSS
.outer_box {
height: 500px;
}
.container {
width: 30%;
height: 100%;
background-color: grey;
float:left
}
.box {
background-color: blue;
height: 84%;
}
.box2 {
background-color: green;
height: 84%;
}
Use height 84% instead of 100%. you can see it in the above link..

How to center group of divs inside div?

I am a bit newbie with CSS and i am pretty obfuscated trying to center a group of divs inside a div. What i want:
divs 2,3 and 4 should be centered inside div1.
My approach:
.div1 {
display: inline-block;
margin: 0 auto;
text-align: center;
}
.restofdivs {
width: 470px;
margin: 20px;
min-height: 1px;
float:center
}
the result is: the 3 divs (2,3 and 4) one on top of another...
Regards,
This can easily be done with table display:
.table-display {
display: table;
width: 100%;
}
.cell-display {
display: table-cell;
}
.div1, .div2, .div3, .div4 {
padding: 40px;
}
.div1 {
background: #ABC;
}
.div2 {
background: #DEF;
}
.div3 {
background: #CAD;
}
.div4 {
background: #FAD;
}
<div class="div1">
<div class="table-display">
<div class="cell-display div2"></div>
<div class="cell-display">
<div class="div3"></div>
<div class="div4"></div>
</div>
</div>
</div>
Maybe set a width on .div1 and remove inline-block from .div1
.div1 {
width: 960px;
margin: 0 auto;
text-align: center;
}
.restofdivs {
width: 470px;
margin: 20px;
min-height: 1px;
}
The most common way to center a block element if you know it's width is to define the width and use "margin: 0 auto". This tells the browser to give a top and bottom margin of 0, and to automatically determine equal margins on the left and right.
Using floats, you can create the layout you described as follows:
http://jsfiddle.net/ynt4suee/
Markup:
<div>
<div id="one" class="border clearfix">one
<div id="wrapper">
<div id="two" class="border">two</div>
<div class="subcontainer">
<div id="three" class="border">three</div>
<div id="four" class="border">four</div>
</div>
</div>
</div>
CSS:
div.border{
border: 1px solid red;
}
div#wrapper{
width: 400px;
margin: 0 auto;
}
div#two{
width: 250px;
float: left;
}
div.subcontainer{
float: right;
width: 130px;
}
.clearfix:after {
content: " "; /* Older browser do not support empty content */
visibility: hidden;
display: block;
height: 0;
clear: both;
}
Here's another approach, using inline-block elements for the inner divs instead:
http://jsfiddle.net/xojqq4v5/
Markup:
<div id="one" class="border">
div 1
<div id="wrapper">
<div id="two" class="border">div 2</div>
<div id="subcontainer">
<div id="three" class="border">div 3</div>
<div id="four" class="border">div 4</div>
</div>
</div>
</div>
CSS:
div.border{
border: 1px solid red;
margin-bottom: 5px;
}
div#wrapper{
width: 450px;
margin: 0 auto;
}
div#two, div#subcontainer{
display: inline-block;
vertical-align: top;
}
div#two{
width: 300px;
}
div#three, div#four{
width: 140px;
}
Still, so long as you know the total width of the inner divs, you can center the wrapper using "margin: 0 auto", which has the advantage of not centering text on all child elements unless otherwise specified.
The difference here is that to lay out the inner divs in columns, div 2 and the container div containing divs 3 and 4 are defined as inline-block elements.

2 column layout issue - stacking and floating

Probably a fairly basic solution to this, but I can't seem to figure it out... have set up a jsfiddle to demonstrate:
http://jsfiddle.net/AxKq8/1/
HTML
<div class="wrapper">
<div id="box-1" class="box">
</div>
<div id="box-2" class="box">
</div>
<div id="box-3" class="box">
</div>
</div>
CSS
.wrapper{
width: 100%;
}
.box {
width: 50%;
}
#box-1 {
height: 200px;
background-color: blue;
}
#box-2 {
height: 100px;
background-color: red;
}
#box-3 {
height: 300px;
float:right;
background-color: green;
position: relative;
top:0px;
right:0px;
}
I have 3 divs. What I'd like to do is have the top of the green div align with the top of the blue div.
As you can see I tried floating the first two divs left, and the third div right. That didn't work, so tried a relative positioning. Also tried using clear aswell, but it's eluding me!
Any suggestions on how to make this work?
Thanks!
Jon
Positioned the third div absolute with top:0
#box-3 {
height: 300px;
float:right;
background-color: green;
position: absolute;
top:0px;
right:0px;
}
Working CODE:JSFIDDLE
You can put the blue and red box in a container, and then a green box in another container. Float the two containers rather than the boxes.
http://jsfiddle.net/AxKq8/9/
HTML
<div class="wrapper">
<div class="container">
<div id="box-1" class="box">
</div>
<div id="box-2" class="box">
</div>
</div>
<div class="container">
<div id="box-3" class="box">
</div>
</div>
</div>
CSS
.wrapper{
width: 100%;
}
.container {
float: left;
width: 50%
}
#box-1 {
height: 200px;
background-color: blue;
}
#box-2 {
height: 100px;
background-color: red;
}
#box-3 {
height: 300px;
background-color: green;
}
Give this a try: JSFiddle
HTML:
<div class="wrapper">
<div class="box-group box">
<div id="box-1" class="box2"></div>
<div id="box-2" class="box2"></div>
</div>
<div class="box-group box">
<div id="box-3" class="box2"></div>
</div>
</div>
CSS:
.wrapper{ width: 100%; }
.box { width: 50%; }
.box2 { width: 100%; }
.box-group { float: left; }
#box-1 { height: 200px; background-color: blue; }
#box-2 { height: 100px; background-color: red; }
#box-3 { height: 300px; background-color: green; }
I created columns with the .box-group class, I grouped the first two items into the first column div so the stacking and floating will appear properly.