I'm trying to achieve a responsive Layout with:
- A fixed header width width 100% and an height of e.g. 50px
- 3 equal squares on the right, taking over the whole space from the top to the bottom of the page.
- A main content are taking over the remaining space on the page
Currently my code looks like this (jsfiddle) but I can't get the width of the boxes on the right to be set automatically based on the current height in order to be displayed as squares... Does anybody know a solution for this in pure CSS?
HTML:
<div id="mainView">
<div id="content">
</div><!-- content -->
<div id="squaressWrapper">
<div id="square1"></div><!-- dummy -->
<div id="square2"></div><!-- dummy -->
<div id="square3"></div><!-- dummy -->
<div id="square4"></div><!-- dummy -->
</div><!-- squaressWrapper -->
</div><!-- mainView -->
</div><!-- wrapper -->
CSS:
html {
height: 100%;
margin: 0;
padding: 0;
}
body {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
}
#wrapper {
width: 100%;
height: 100%;
display: flex;
display: -webkit-flex;
flex-direction: column;
-webkit-flex-direction: column;
-webkit-align-content: stretch;
align-content: stretch;
}
#header {
height: 50px;
width: 100%;
background: #ffb8c4;
}
#mainView {
flex: 1;
-webkit-flex: 1;
position: relative;
background: #666;
}
#squaressWrapper {
position: absolute;
height: 100%;
background: green;
right: 0;
display: flex;
display: -webkit-flex;
flex-direction: column;
-webkit-flex-direction: column;
-webkit-align-content: stretch;
align-content: stretch;
}
#square1 {
position: relative;
flex: 1;
-webkit-flex: 1;
width: 100px;
border: 2px solid white;
background: green;
}
#square2 {
position: relative;
flex: 1;
-webkit-flex: 1;
width: 100px;
border: 2px solid white;
background: green;
}
#square3 {
position: relative;
flex: 1;
-webkit-flex: 1;
width: 100px;
border: 2px solid white;
background: green;
}
I get a solution, using vh units as suggested by Nicho.
The CSS
#squaressWrapper {
position: absolute;
height: 100%;
width: 33vh;
right: 0;
display: flex;
display: -webkit-flex;
flex-direction: column;
-webkit-flex-direction: column;
-webkit-align-content: stretch;
align-content: stretch;
}
.squares {
position: relative;
flex: 1;
-webkit-flex: 1;
width: calc(100% - 15px);
border: 2px solid white;
background: green;
right: -11px;
}
demo
The dimensions are a little bit strange because setting the width of the container to calc(33vh - 15px) didn't work.
May be in a near future that will be easier.
I don't know what is the browser support for this, I tested it only in Chrome.
Note : 15px is the dimension of the header (45px) divided by the number of squares.
Well I took a shot at this...
I changed your sizes up on your css
here is the link to the fiddle.
http://jsfiddle.net/D7RSP/2/
#header {
height: 20%;
width: 100%;
background: #ffb8c4;
}
#mainView {
flex: 1;
width: 69%;
height: 100%;
float: left;
background: green;
}
.square {
flex: 1;
-webkit-flex: 1;
width: 30%;
border: 1px solid white;
background: green;
height: 25%;
float:right;
}
Related
I'm trying to make an overlap form div (blue) by activity-indicator div (yellow). Both containers should fill all available spaces of parent div, but yellow one (activity indicator) should overlap blue one (input form). I've tried to use position: absolute for activity div, but then I'm loosing parent width and height. What I'm doing wrong and how can it be fixed?
html,
body {
width: 100vw;
height: 100vh;
margin: 0;
background-color: aquamarine;
display: flex;
align-items: center;
justify-content: center;
}
.root-wrapper {
width: 300pt;
height: 440pt;
display: flex;
flex-direction: column;
background-color: gray;
}
.logo {
height: 80pt;
background-color: green;
}
.content-container {
display: flex;
flex-direction: column;
flex: 1 1 auto;
background-color: lightcoral;
padding: 20pt;
box-sizing: border-box;
position: relative;
z-index: 1;
}
.input-form {
position: relative;
flex: 1 1 auto;
background-color: rgb(60, 109, 173);
z-index: 2;
}
.activity-indicator {
position: relative;
flex: 1 1 auto;
background-color: yellow;
z-index: 9;
}
<div class="root-wrapper">
<div class="logo"> </div>
<div class="content-container">
<div class="activity-indicator">
</div>
<div class="input-form">
</div>
</div>
An easy way would be to nudge .input-form up with:
position: relative;
top: -100px;
margin-bottom: -100px;
html,
body {
width: 100vw;
height: 100vh;
margin: 0;
background-color: aquamarine;
display: flex;
align-items: center;
justify-content: center;
}
.root-wrapper {
width: 300pt;
height: 440pt;
display: flex;
flex-direction: column;
background-color: gray;
}
.logo {
height: 80pt;
background-color: green;
}
.content-container {
display: flex;
flex-direction: column;
flex: 1 1 auto;
background-color: lightcoral;
padding: 20pt;
box-sizing: border-box;
position: relative;
z-index: 1;
}
.input-form {
position: relative;
top: -100px;
margin-bottom: -100px;
flex: 1 1 auto;
background-color: rgba(60, 109, 173, .5);
z-index: 10;
}
.activity-indicator {
position: relative;
flex: 1 1 auto;
background-color: yellow;
z-index: 9;
}
<div class="root-wrapper">
<div class="logo"> </div>
<div class="content-container">
<div class="activity-indicator">
</div>
<div class="input-form">
</div>
</div>
I'm trying to create element div that contain 3 part, using 2 row and 2 column.
.flex-row {
flex-direction: row;
display: flex;
width: 310px;
}
.flex-column {
flex-direction: column;
display: flex;
}
.flex-body {
display: flex;
margin: 40px 10px 0px 0px;
}
.flex-body div:not([class*="flex"]) {
border: 1px solid white;
flex: 1 1 260px;
width: 764px;
}
<div class="flex-body">
<div class="flex-row">
<div style="background: #0980cc;"></div>
</div>
<div class="flex-column">
<div style="background: #09cc69;"></div>
<div style="background: #cc092f;"></div>
</div>
</div>
I set the width because if I didn't do it, the width wouldn't fit page.
But the div isn't responsive. I've tried but nothing work. How can I make my div responsive the screen resolution?
I've just created a version that uses percentages:
body,
html {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
border: 0;
}
.flex-body {
display: flex;
width: 100%;
height: 100%;
box-sizing: border-box;
padding: 40px;
}
.flex-body div:not([class*="flex"]) {
border: 1px solid white;
flex: 1 1 50%;
position: relative;
box-sizing: border-box;
}
.flex-row {
flex-direction: row;
display: flex;
width: 35%;
background-color: #0980cc;
}
.flex-column {
flex-direction: column;
display: flex;
width: 65%;
}
.flex-column div:nth-child(1) {
background: #09cc69;
width: 100%;
}
.flex-column div:nth-child(2) {
background: #cc092f;
width: 100%;
}
jsfiddle link
I need to assign a dimension of height: 50px to
.panelDraggable__header
.panelDraggable__info
.panelDraggable__footer
Using the following code I am not able to set the height, if you trying to inspect .panelDraggable__header its computed value is 18px.
Only way is when I adjust the position to absolute, which disrupt my layout.
How to solve this problem?
What is in general the best way to add the right dimension to a flex box?
Should I use flex-basis instead?
#panelDevTools {
position: fixed;
top: 25px;
left: 50px;
width: 260px;
height: 300px;
background-color: yellow;
}
.panelDraggable {
display: flex;
-webkit-flex: auto;
-ms-flex: auto;
flex: auto;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.panelDraggable__header {
order: 0;
background-color: greenyellow;
height: 50px;
}
.panelDraggable__info {
order: 1;
background-color: lightseagreen;
height: 50px;
}
.panelDraggable__content {
order: 3;
background-color: slategrey;
}
.panelDraggable__footer {
order: 4;
background-color: blueviolet;
height: 50px;
}
<div data-ntv-type="PanelDevTools" class="panelDraggable" id="panelDevTools" widgetid="panelDevTools">
<div id="panelDevTools__info" class="panelDraggable__info">Tools for developement</div>
<div id="panelDevTools__content" class="panelDraggable__content">
<div id="cnt-inner" style="height:800px;width:50px;background-color:red;"></div>
</div>
<div id="panelDevTools__footer" class="panelDraggable__footer ">Footer</div>
<div id="panelDevTools__header" class="panelDraggable__header">
<div id="panelDevTools__title" class="panelDraggable__title">Developer Tools</div>
<div id="panelDevTools__handle" class="panelDraggable__handle"></div>
<div id="panelDevTools__help" class="panelDraggable__help"></div>
</div>
</div>
just use min-height instead of height as you actually what the height to be flexible but at least 50px
#panelDevTools {
position: fixed;
top: 25px;
left: 50px;
width: 260px;
height: 300px;
background-color: yellow;
}
.panelDraggable {
display: flex;
-webkit-flex: auto;
-ms-flex: auto;
flex: auto;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.panelDraggable__header {
order: 0;
background-color: greenyellow;
min-height: 50px;
}
.panelDraggable__info {
order: 1;
background-color: lightseagreen;
min-height: 50px;
}
.panelDraggable__content {
order: 3;
background-color: slategrey;
}
.panelDraggable__footer {
order: 4;
background-color: blueviolet;
min-height: 50px;
}
<div data-ntv-type="PanelDevTools" class="panelDraggable" id="panelDevTools" widgetid="panelDevTools">
<div id="panelDevTools__info" class="panelDraggable__info">Tools for developement</div>
<div id="panelDevTools__content" class="panelDraggable__content">
<div id="cnt-inner" style="height:800px;width:50px;background-color:red;"></div>
</div>
<div id="panelDevTools__footer" class="panelDraggable__footer ">Footer</div>
<div id="panelDevTools__header" class="panelDraggable__header">
<div id="panelDevTools__title" class="panelDraggable__title">Developer Tools</div>
<div id="panelDevTools__handle" class="panelDraggable__handle"></div>
<div id="panelDevTools__help" class="panelDraggable__help"></div>
</div>
</div>
I have an HTML page with header/content/footer that uses flexbox model and contains <details> tag.
I need to make details content use maximum available height, meaning that when in opened state its content should occupy all space in its container (except for summary of course).
Here is my HTML/CSS code (http://jsfiddle.net/rtojycvk/2/):
HTML:
<div class="wrapper">
<div class="header">Header</div>
<div class="main">
Some text before details
<details class="details" open>
<summary>Details summary</summary>
<div class="content">Details content</div>
</details>
</div>
<div class="footer">Footer</div>
</div>
CSS:
html, body {
height: 100%;
margin: 0; padding: 0;
}
.wrapper {
display: flex;
flex-direction: column;
width: 100%;
min-height: 100%;
}
.header {
height: 50px;
background-color: yellow;
flex: 0 0 auto;
}
.main {
background-color: cyan;
flex: 1;
display: flex;
flex-direction: column;
}
.footer {
height: 50px;
background-color: green;
flex: 0 0 auto;
}
.content {
background-color: blue;
color: white;
flex: 1;
}
.details {
background-color: red;
flex: 1;
display: flex;
flex-direction: column;
}
As you can see, the details tag itself takes all the available space, but not its content.
P.S. I need this to work only in Chrome.
http://jsfiddle.net/rtojycvk/16/
use position absolute on content, position relative on details, and calc() css (to offset the summary height)
.content {
background-color: lightgray;
color: black;
flex: 1;
display:flex;
position:absolute;
height: calc(100% - 18px);
width: 100%;
}
.details {
background-color: gray;
flex: 1;
display: flex;
flex-direction: column;
position:relative;
}
hope this helps! (I changed the colors cause they were a bit bright for me :p)
Absolute positioned .content and details relative.
fiddle
html, body {
height: 100%;
margin: 0; padding: 0;
}
.wrapper {
display: flex;
flex-direction: column;
width: 100%;
min-height: 100%;
}
.header {
height: 50px;
background-color: yellow;
flex: 0 0 auto;
}
.main {
background-color: cyan;
flex: 1;
display: flex;
flex-direction: column;
}
.footer {
height: 50px;
background-color: green;
flex: 0 0 auto;
}
.content {
background-color: blue;
color: white;
flex: 1;
position: absolute;
top: 3%;
bottom: 0;
height: 97%;
width: 100%;
}
details {
position: relative;
}
summary{
height: 3%;
}
.details {
background-color: red;
flex: 1;
display: flex;
flex-direction: column;
}
For those who prefer not to set absolutes positions, or can't do it, there is another way to accomplish it: using vh for height of .content:
html,
body {
margin: 0;
padding: 0;
height:100vh;
background: orange;
}
.wrapper {
display: flex;
flex-direction: column;
width: 100%;
height:100vh;
background: pink;
}
.header,
.footer {
height: 10vh;
min-height: 25px; /* (or max-height, or both!) */
max-height: 50px;
background-color: yellow;
flex: 0 0 auto;
}
.footer {
background-color: green;
}
.main {
background-color: cyan;
flex: 1;
display: flex;
flex-direction: column;
height: calc(100vh - 20vh); /* 10vh * 2 (.header + .footer sizes) */
}
.content {
background-color: blue;
color: white;
flex: 1;
display: flex;
flex-direction: column;
height: calc(100vh - 20vh); /* 10vh * 2 (.header + .footer sizes) */
}
.details {
background-color: red;
flex: 1;
display: flex;
flex-direction: column;
}
<div class="wrapper">
<header class="header">Header</header>
<main class="main">
Some text before details
<details class="details" open>
<summary>Details summary</summary>
<div class="content">Details content</div>
</details>
</main>
<footer class="footer">Footer</footer>
</div>
Fiddle's here: http://jsfiddle.net/ALXWebDev/wxm0v49c/
Hope it helps!
I try to make a responsive website which looks similar in Chrome, IE(11), and FF.
My problem in IE is, that if the site is too long the scrollbar doesn't scroll to the end because of the sticky page-footer('page-footer'). I tried to give my page-main-area a margin or padding bottom but that doesn't change anything.
Another thing is that my sidebar background doesn't fill to the end.
CSS extract:
.page-sidebar {
padding: 10px;
border-top: 2px solid #000;
background-color: #00BB9C;
width: 100%;
padding-bottom: 58px;
}
.page-sidebar h3 {
color: black;
}
.page-sidebar h3:first-child {
margin-top: 0;
}
.page {
display: -webkit-flex;
display: -ms-flex;
display: flex;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
min-height: 100%;
max-width: 900px;
margin-left: auto;
margin-right: auto;
}
.page-main-area {
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
}
.page-footer {
position: fixed;
bottom: 0;
width: 100%;
max-width: 900px;
margin: 0 auto;
padding: 8px;
background-color: #000;
color: #fff;
max-height: 50px;
}
HTML + CSS:
http://jsfiddle.net/mvz8rq1o/2/
What can i do to fix this in IE?
margin-bottom: on page-sidebar should get the full sidebar showing. (won't fix the fill-to-bottom however...)