Make flex items on second row take remaining height of container - html

I am trying to create a layout with a header on top, underneath it a sidebar and the main content.
I would like to have the sidebar and the content view take over the vertical space left by the header. The problem is that the header can dynamically re-size so I cannot perform a calc(). My solution was to use the flexbox scheme.
I divided the viewport horizontally into two parts. One is the header and one is a wrapper for the sidebar and main content.
The sidebar is floated left and given a percentage of the width and the content is floated right and given the rest.
The problem is that I am trying to make the sidebar always be 100% height of the wrapper.
I tried height: 100% and min-height: 100% but these do not work.
I do not wish to absolutely position it since if the wrapper were to overflow with the main content, the sidebar would not expand accordingly.
Here is my pen: http://codepen.io/markt5000/pen/JXNXpW
As you can see the orange is the header and the red space is the wrapper with the sidebar and the content.
here is the layout
<div class="header">
</div>
<div class="row">
<div id="sidebar">
</div>
<div id="main-content">
</div>
</div>

There's no need for:
height, min-height or calc on your flex items
absolute positioning
floats (in fact, they're useless because floats are ignored in a flex formatting context)
Flex properties have all the power you need to make the layout work. The key is to use flex: 1 to make items expand the full available length of the container.
So your header's height can be dynamic and the sidebar and main content can be made to consume whatever height remains. No scrollbars.
Here's your code with some revisions:
html { height: 100%; }
body {
height: 100%;
margin: 0;
padding: 0;
}
.outer-flex-container {
height: 100%;
display: flex;
flex-direction: column; /* main flex container stacks items vertically */
}
.header {
height: 80px; /* demo purposes; from your original code */
background-color: orange;
}
.nested-flex-container {
display: flex; /* inner flex container stacks items horizontally */
flex: 1; /* KEY RULE: tells this second flex item of main container
to consume all available height */
align-items: stretch; /* KEY RULE: default setting. No need to include. Tells
children to stretch the full length of the container
along the cross-axis (vertically, in this case). */
}
.sidebar {
flex-basis: 20%; /* set width to 20% */
background-color: aqua;
}
.content {
flex: 1; /* set width to whatever space remains */
background: magenta;
}
<div class="outer-flex-container">
<div class="header">HEADER</div><!-- main flex item #1 -->
<div class="nested-flex-container"><!-- main flex item #2 -->
<div class="sidebar">SIDEBAR</div><!-- inner flex item #1 -->
<div class="content">MAIN CONTENT</div><!-- inner flex item #2 -->
</div><!-- close inner flex container -->
</div><!-- close outer flex container -->
Revised Codepn

Is this what you're going for? http://codepen.io/Shambolaz/pen/xVdVyd
.view .row
{
flex: 1 1 auto;
background:red;
height: 90%;
}

When content is larger than it's element, to get true 'fixed position' behavior add overflow: auto to the content element.
Also make sure height is concretely specified for all parents of the content element.
By that I mean there must be an ancestor element that has a specified height (either fixed px or 100vh).
Stack Overflow puts the snippet in an iFrame, which has a fixed-height parent, so the elements using height: 100% have something to calculate from.
We can therefore just add height: 100% to the content div, and the scrollbar will show up there.
This is the modified pen (also has a fixed height ancestor). You can experiment by removing the height CSS rules at various points, and see the scrollbar move up the element tree.
html { height: 100%; }
body {
height: 100%;
margin: 0;
padding: 0;
}
.outer-flex-container {
display: flex;
flex-direction: column;
height: 100%;
}
.header {
height: 80px;
background-color: orange;
}
.nested-flex-container {
display: flex;
flex: 1;
}
.sidebar {
flex-basis: 20%;
background-color: aqua;
}
.content {
flex: 1;
background: magenta;
overflow-y: auto;
height: 100%;
}
<div class="outer-flex-container">
<div class="header">HEADER</div><!-- main flex item #1 -->
<div class="nested-flex-container"><!-- main flex item #2 -->
<div class="sidebar">SIDEBAR</div><!-- inner flex item #1 -->
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Porttitor eget dolor morbi non arcu risus quis varius quam. Commodo viverra maecenas accumsan lacus. Vitae elementum curabitur vitae nunc sed velit dignissim. Auctor urna nunc id cursus metus aliquam eleifend. Bibendum ut tristique et egestas. Orci phasellus egestas tellus rutrum tellus pellentesque eu tincidunt. Diam maecenas ultricies mi eget mauris pharetra et. Ultricies mi eget mauris pharetra. Nibh mauris cursus mattis molestie.
<br/>
Urna neque viverra justo nec ultrices dui sapien. Diam vulputate ut pharetra sit amet aliquam id diam maecenas. Nunc non blandit massa enim nec dui nunc. Amet mattis vulputate enim nulla. Nisl condimentum id venenatis a condimentum vitae sapien. Magna sit amet purus gravida quis blandit turpis. Sed turpis tincidunt id aliquet risus. Aliquet lectus proin nibh nisl condimentum id venenatis a. Vitae purus faucibus ornare suspendisse sed. Sit amet commodo nulla facilisi nullam. Egestas fringilla phasellus faucibus scelerisque eleifend. Facilisi etiam dignissim diam quis enim lobortis scelerisque fermentum. Viverra adipiscing at in tellus integer feugiat. Scelerisque eu ultrices vitae auctor eu augue. At urna condimentum mattis pellentesque.
<br/>
Quisque id diam vel quam elementum pulvinar etiam non quam. Morbi tempus iaculis urna id volutpat lacus laoreet non curabitur. Diam quis enim lobortis scelerisque fermentum dui. Tortor id aliquet lectus proin nibh. Pellentesque pulvinar pellentesque habitant morbi tristique senectus et netus. Egestas fringilla phasellus faucibus scelerisque. Venenatis a condimentum vitae sapien pellentesque habitant. Quis vel eros donec ac odio tempor orci. Ultrices sagittis orci a scelerisque. Ligula ullamcorper malesuada proin libero nunc consequat interdum. Dis parturient montes nascetur ridiculus mus mauris. Nisl vel pretium lectus quam id leo in vitae. Euismod elementum nisi quis eleifend quam adipiscing vitae. Mattis vulputate enim nulla aliquet porttitor lacus luctus accumsan. Urna porttitor rhoncus dolor purus non. Lobortis mattis aliquam faucibus purus in massa tempor nec. Risus pretium quam vulputate dignissim suspendisse in. Malesuada bibendum arcu vitae elementum curabitur. Quisque id diam vel quam elementum pulvinar. A erat nam at lectus urna duis convallis.
<br/>
Nulla facilisi nullam vehicula ipsum. Nibh ipsum consequat nisl vel pretium lectus quam id leo. Morbi tristique senectus et netus et malesuada fames ac turpis. Quis imperdiet massa tincidunt nunc pulvinar sapien. Amet volutpat consequat mauris nunc congue nisi vitae. Feugiat sed lectus vestibulum mattis ullamcorper. Pharetra magna ac placerat vestibulum lectus. Sed faucibus turpis in eu mi bibendum neque egestas. A condimentum vitae sapien pellentesque habitant. Mi bibendum neque egestas congue quisque egestas diam. Vulputate odio ut enim blandit volutpat maecenas volutpat blandit. Lacus luctus accumsan tortor posuere ac ut.
<br/>
Sit amet cursus sit amet dictum. Sem integer vitae justo eget magna fermentum iaculis eu non. Etiam dignissim diam quis enim lobortis scelerisque fermentum dui faucibus. Congue mauris rhoncus aenean vel elit scelerisque mauris pellentesque pulvinar. Facilisis gravida neque convallis a cras semper. Nullam vehicula ipsum a arcu. Sed egestas egestas fringilla phasellus faucibus scelerisque eleifend donec pretium. Et odio pellentesque diam volutpat commodo sed egestas egestas. Velit aliquet sagittis id consectetur. Faucibus vitae aliquet nec ullamcorper. In iaculis nunc sed augue lacus viverra. Vitae semper quis lectus nulla at volutpat diam ut venenatis. Et malesuada fames ac turpis. Felis imperdiet proin fermentum leo vel. Fringilla est ullamcorper eget nulla facilisi etiam dignissim. Quis varius quam quisque id diam vel quam. Ornare arcu dui vivamus arcu felis bibendum ut. Turpis massa sed elementum tempus egestas sed. Morbi tincidunt augue interdum velit euismod in pellentesque massa placerat. Arcu ac tortor dignissim convallis aenean et tortor.
</div><!-- inner flex item #2 -->
</div><!-- close inner flex container -->
</div><!-- close outer flex container -->

Related

How to make flex child to have width 100% of it's parent's parent?

I have a flex child, inside a scrollable flex column. I want it to set its width to 100% of the scrollable flex column's parent.
It's because I want to have a notifications bar, and it automatically opens if a new notification arrives, and currently the contents of the scrollable flex are jumping around (every item is flex).
Let me demonstrate:
div {
display: flex;
}
.row {
flex-direction: row;
}
.col {
flex-direction: column;
}
.target-width {
height: 100%;
width: 500px;
height: 500px;
}
.scrollable {
overflow: scroll;
height: 100%;
flex: 1;
}
.content {
background: yellow;
width: 100%;
height: 100%;
}
.notifications {
background: blue;
height: 100%;
flex-basis: 200px;
}
<div class='row target-width'>
<div class='col scrollable'>
<div class='col content'>content</div>
</div>
<div class='col notifications'></div>
</div>
At the above example I would expect content to have width of 500px, even though its direct parent scrollable has a width of 300px.
Let's assume that every width, and height is unknown, the above are just for demonstration. So all we know is we want to set content's width as width of target-width. Not knowing exactly the width of target-width, is there a way to make that work?
I think I understand your need and I'm not really sure if it can be done only with css.
Here is a JS code that can solve your problem. Please keep in mind that my solution maybe is not the best one, but I think It's a starting point.
Put this code into Head:
<script type="text/javascript">
function setContentWidth() {
var elementTW = document.querySelector('.target-width');
var styleTW = window.getComputedStyle(elementTW);
var widthTW = styleTW.width;
document.querySelector(".content").setAttribute("style","width:" + parseInt(widthTW) +"px" );
}
window.onload = setContentWidth;
</script>
Edited my answer to fit the question. Now content receive the parent width.
Tell me if this solve your problem or you need further assistance.
I am not sure if it is the solution to what you are looking for. I have applied some changes to the code to reproduce what I think I understand you want to achieve. Could you review it and tell me if it is the result you are looking for?
div {
display: flex;
box-sizing: border-box;
}
.row {
flex-direction: row;
}
.col {
flex-direction: column;
}
.target-width {
/*width:500px;*/
width: 100%;
height: 100vh;
position:relative;
}
.scrollable {
overflow-y:hidden;
overflow-x: auto;
height: 100%;
width:100%;
flex: 1;
}
.content {
background: yellow;
width: 100vw;
height: 100%;
}
.notifications {
background: blue;
opacity:.5;
height: 100vh;
width: 100px;
position:absolute;
z-index:1;
right:0;
}
<div class='row target-width'>
<div class='col scrollable'>
<div class='col content'>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent aliquam quis erat ut rhoncus. Nunc non sollicitudin eros. Vivamus sollicitudin, orci vitae congue rutrum, lacus nulla blandit dolor, nec egestas est est eu est. Donec mi metus, tempor quis ante quis, viverra ornare nulla. Aliquam fringilla pharetra nisi, ac bibendum tortor rhoncus auctor. Sed quam elit, finibus vel dignissim rhoncus, viverra ut risus. Sed placerat, massa et vehicula feugiat, ex augue pulvinar tortor, eget sodales sem libero non metus. Fusce laoreet sollicitudin erat a posuere. Mauris at sem metus. Sed posuere quam bibendum malesuada auctor. Ut pulvinar eros quis massa molestie, sed tempus urna ultrices. Vivamus arcu turpis, porta ut vehicula at, dapibus vitae massa.
Nulla facilisi. Curabitur a dignissim purus. Morbi rhoncus sit amet mauris sed viverra. Sed eget justo eget dui commodo vehicula. Pellentesque convallis ultricies quam, ac maximus purus mollis vitae. Nam ut erat erat. Ut ultrices quam magna, vel efficitur massa finibus nec. Maecenas turpis tellus, tempus ut iaculis quis, elementum rhoncus nunc. Quisque egestas condimentum nunc, non feugiat erat malesuada eu. Donec in justo ullamcorper, molestie justo ac, elementum leo. Morbi ultricies et sapien sit amet bibendum. Sed ornare eget lectus vel tempor. Suspendisse sodales ipsum in tincidunt dictum. Duis placerat ligula ac sem imperdiet sollicitudin.
Pellentesque ex risus, rutrum vel mi sed, egestas faucibus nisl. Mauris rutrum sem justo, eget posuere neque aliquam non. Sed molestie neque mauris, quis gravida turpis rutrum eget. Duis eu mauris vitae arcu suscipit sagittis. Duis aliquam tortor quis massa placerat vestibulum. Fusce eu purus non eros ornare aliquam a accumsan turpis. Maecenas eu nunc dignissim, ornare diam et, malesuada est.
Donec eu commodo libero. Donec fermentum metus in quam lobortis, ut eleifend felis posuere. Donec sed leo malesuada, viverra tellus sit amet, egestas leo. Cras tempus, ex et tincidunt varius, magna mauris dignissim ex, in mattis dui erat eu arcu. Praesent tristique faucibus massa eget malesuada. Aliquam vitae enim quam. Phasellus maximus ullamcorper leo, auctor luctus ipsum volutpat quis. Ut nec neque non felis bibendum ultricies. Cras leo odio, condimentum et eros at, feugiat lacinia sem. Sed odio sem, lobortis sed enim vitae, bibendum faucibus velit. Ut eget diam consequat, imperdiet sem at, hendrerit ligula. Mauris egestas consequat magna, gravida fermentum leo malesuada pellentesque. Sed non pellentesque purus, at congue arcu.<br/></div>
</div>
<div class='col notifications'>
</div>
</div>

how to add multiple background images on a page but NOT stacked on top of each other

I want the background images to be horizontally on top of each other. So for instance:
PIC 1
PIC 2
PIC 3
Right now, the only solutions I'm seeing to this problem are to stack the photos because that's what most people are asking about, but I don't want to stack the photos. I just want them to be touching each other (or not, that's fine too) but not on top of each other (from a 3d point of view). The reason why I'm still using them as background images, in case you're wondering, is because I want there to be text on the images, as well as anything else I want to implement. Also, I like having the background-size as cover, but I need to change the formatting so that the position of the two images do not overlap.
Background image placement, sizing and cropping is a rather complex matter in CSS, for a very simple reason: to cover all possible cases.
Now, in theory, you could use a comma separated list of URL's, inside the background-image property and also specify the following properties (if needed) as lists of comma separated properties:
background-attachment
background-clip
background-image
background-origin
background-position
background-repeat
background-size
Needless to say, the first item in the list for each of the above applies to the first image, and so on...
For example:
body {
background-image: url("https://source.unsplash.com/random/800x600"), url("https://source.unsplash.com/random/600x800"), url("https://source.unsplash.com/random/700x700");
background-position: top center, center center, bottom center;
background-size: auto 33.33%, auto 33.33%, auto 33.33%;
background-repeat: repeat-x, repeat-y, repeat-x;
margin: 0;
min-height: 100vh;
}
If you find it more convenient, you can also use the list notation with the background shorthand property, as in:
body { background: url(https://source.unsplash.com/random/800x600) repeat-x top center /100% 33.33%, url(https://source.unsplash.com/random/600x800) repeat-y center center /100% 33.33%, url(https://source.unsplash.com/random/800x200) repeat-x bottom center /100% 33.33%;
margin: 0;
min-height: 100vh;
}
However, the real problem is you are requesting a more advanced logic, which requires background images to influence each other's position, sizing and cropping, pretty much like DOM element would.
Tough luck. That's not possible. Each element in the list of background-images is a separate layer which is rendered by itself, without regard to whether other background-image layers exist. The first one is rendered above the second one which is rendered above the third, etc...
If you think about it, considering the array of possible combinations, it's unrealistic to request the background property of a single element to handle all cases, considering responsiveness.
That's why the proper way to go here, instead of using the background property, is to create a child item in your element with the purpose of controlling the background display according to the design specs.
You want to give .parent (feel free to change the class name) position:relative and give <background-sizer> element position:absolute; width:100%; height: 100%; top:0; left:0;, making sure it covers the entire area of its closest positioned parent. Inside <background-sizer> you will probably want to add some dummy <span>s to help you control the background, eventually using #media queries, if you need them displayed differently on different devices.
Here's an example:
body {
margin: 0;
}
.parent {
position: relative;
padding: 2rem;
}
background-sizer {
position: absolute;
top: 0; left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
}
background-sizer > span {
flex: 1;
background-size: cover;
border: solid rgba(255,255,255,.35);
border-width: 1px 0;
}
background-sizer::after {
content: '';
position: absolute;
width: 100%;
height: 100%;
background: rgba(0,0,0,.15);
top: 0;
height: 100%;
z-index: 1;
}
background-sizer > span:nth-child(1) {
background-image: url(https://source.unsplash.com/random/800x500);
}
background-sizer > span:nth-child(2) {
background-image: url(https://source.unsplash.com/random/500x800);
}
background-sizer > span:nth-child(3) {
background-image: url(https://source.unsplash.com/random/500x500);
}
.contents {
position: relative;
background-color: rgba(0,0,0,.42);
border: 1px solid white;
padding: 1rem;
box-sizing: border-box;
z-index: 1;
color: white;
}
.some-more-content {
padding: 0 2rem;
}
body > * {
margin: 0 auto;
max-width: 800px;
}
.contents {
opacity: 1;
transition: opacity .4s ease-in-out;
}
.contents:hover {
opacity: .21;
}
<div class="parent">
<background-sizer>
<span></span>
<span></span>
<span></span>
</background-sizer>
<div class="contents">
<h2>This is your element</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ultrices in iaculis nunc sed. Morbi blandit cursus risus at ultrices mi tempus imperdiet. Accumsan lacus vel facilisis volutpat est velit. Platea dictumst vestibulum rhoncus est pellentesque elit ullamcorper dignissim. Sem nulla pharetra diam sit amet. Mattis ullamcorper velit sed ullamcorper morbi tincidunt. Elementum nisi quis eleifend quam adipiscing. Id neque aliquam vestibulum morbi blandit cursus risus. At consectetur lorem donec massa sapien faucibus et molestie ac. Faucibus interdum posuere lorem ipsum dolor. Congue nisi vitae suscipit tellus mauris a. At quis risus sed vulputate odio. Massa tincidunt dui ut ornare lectus sit. Tincidunt nunc pulvinar sapien et ligula. Mauris augue neque gravida in fermentum et sollicitudin ac. Quisque id diam vel quam elementum. Parturient montes nascetur ridiculus mus mauris vitae ultricies leo. Lacus vestibulum sed arcu non odio euismod lacinia. Et ultrices neque ornare aenean euismod elementum nisi quis.
<p>Rutrum tellus pellentesque eu tincidunt tortor. Pellentesque massa placerat duis ultricies lacus sed turpis. Ornare aenean euismod elementum nisi quis eleifend quam adipiscing. Lectus quam id leo in vitae. Et malesuada fames ac turpis. Aliquam vestibulum morbi blandit cursus. Pellentesque habitant morbi tristique senectus et netus. Nunc lobortis mattis aliquam faucibus purus in massa tempor. Vitae semper quis lectus nulla at volutpat. Ac ut consequat semper viverra nam libero justo. Fusce ut placerat orci nulla pellentesque dignissim.
<p>Lacus sed turpis tincidunt id aliquet risus feugiat. Mauris rhoncus aenean vel elit scelerisque mauris pellentesque. Facilisis mauris sit amet massa vitae tortor condimentum lacinia. Sodales ut etiam sit amet nisl purus in mollis nunc. Habitant morbi tristique senectus et netus et. Tortor dignissim convallis aenean et tortor at. Arcu vitae elementum curabitur vitae. Eget nunc scelerisque viverra mauris in aliquam sem. Posuere morbi leo urna molestie at. Magna eget est lorem ipsum dolor. Integer vitae justo eget magna. A pellentesque sit amet porttitor eget dolor. Egestas diam in arcu cursus euismod. Libero enim sed faucibus turpis.
</div>
</div>
<div class="some-more-content">
<h2>And here's some more content</h2>
<p>Turpis cursus in hac habitasse platea dictumst quisque sagittis. In massa tempor nec feugiat nisl pretium fusce id velit. Neque volutpat ac tincidunt vitae semper quis. Sit amet porttitor eget dolor morbi non arcu risus. Ut venenatis tellus in metus vulputate eu scelerisque felis. Id eu nisl nunc mi ipsum faucibus vitae. Ut diam quam nulla porttitor massa. Nec feugiat in fermentum posuere urna nec tincidunt praesent semper. Commodo ullamcorper a lacus vestibulum. Et sollicitudin ac orci phasellus egestas tellus. Vulputate dignissim suspendisse in est ante in nibh mauris cursus. Pellentesque sit amet porttitor eget dolor. Sed cras ornare arcu dui.
<p>Id semper risus in hendrerit gravida rutrum quisque non. Amet luctus venenatis lectus magna fringilla. Adipiscing bibendum est ultricies integer quis auctor elit sed vulputate. Purus semper eget duis at tellus. Integer quis auctor elit sed vulputate mi sit amet mauris. Pulvinar mattis nunc sed blandit libero volutpat sed cras ornare. Faucibus turpis in eu mi bibendum neque. Ultrices neque ornare aenean euismod elementum nisi quis. Risus viverra adipiscing at in tellus integer feugiat. Tempor orci dapibus ultrices in iaculis nunc sed augue. Pharetra massa massa ultricies mi quis hendrerit. Tellus orci ac auctor augue mauris. Neque volutpat ac tincidunt vitae semper. Sit amet facilisis magna etiam tempor orci. Elementum facilisis leo vel fringilla est ullamcorper eget nulla. Nibh tortor id aliquet lectus. Blandit cursus risus at ultrices mi.
</div>
A few notes:
intended as proof of concept (copy/paste won't help you much); you should take the time to read what the properties do, in order to use it. If you don't, chances are you won't be able to adapt it to your needs.
most likely, you don't need any of the cosmetics (padding, margin, color, etc...)
i placed a darkening layer on the <background-sizer> to make sure the text remains readable, given the images are randomly generated. You probably want to that.

Flex: take remaining free space of screen height [duplicate]

This question already has answers here:
Fill the remaining height or width in a flex container
(2 answers)
Make a div fill the height of the remaining screen space
(41 answers)
Closed 5 years ago.
This is the typical adaptive layout problem:
Header is always at the top of the screen.
Footer is always at the bottom of the screen.
We should not set the header and footer height: it calculates naturally from contains height and paddings. So, the solution with height calculating and positioning will not use here.
The middle section is scrollable. It must take all remaining space between header and footer.
Flex will help here. However: how I should to setup the middle section to make it take remaining space between header and footer? I almost did it, but it is not perfect yet: there is the extra scrollbar remains.
*{
box-sizing: border-box;
}
.flexContainter {
display: flex;
flex-direction: column;
height: 100vh
}
.header{
background: teal;
padding: 5px;
flex-shrink: 0; /* header must not shrink in any case */
}
.header > .dummyContains{
height: 20px;
background-color: HotPink;
}
.footer{
margin-top: auto;
background: DarkSalmon ;
padding: 5px;
flex-shrink: 0; /* header must not shrink in any case */
}
.footer > .dummyContains{
height: 20px;
background: LightGreen;
}
.middle{
background: LavenderBlush;
overflow-y: scroll;
}
<div class="flexContainter">
<div class="header">
<div class="dummyContains"></div>
</div>
<div class="middle">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pellentesque eu sem fermentum dapibus. Curabitur sollicitudin nec magna quis imperdiet. Morbi auctor massa nisi, non hendrerit leo faucibus sed. Donec pulvinar, dolor eget consequat semper, quam est ullamcorper nunc, vel rutrum justo lacus eget neque. Nunc fermentum, velit quis consectetur scelerisque, justo velit vestibulum nunc, vitae malesuada metus nulla eget eros. Vestibulum porta at justo ut condimentum. In consectetur mattis eros eget porttitor. Nam dapibus mi a lobortis tristique. Vestibulum et semper urna. Aliquam lacinia felis a tortor viverra, quis posuere orci vehicula. Integer varius laoreet elementum. Pellentesque varius metus arcu. Aliquam sodales nisi vitae diam convallis, non luctus nisl ultrices. Etiam faucibus dui non elit bibendum finibus. Nulla vulputate a sem eu semper. Morbi vel mattis elit. Nullam velit nibh, laoreet non ligula at, luctus faucibus mi. Duis non maximus ligula. Phasellus convallis eros quis justo gravida molestie.
Suspendisse sit amet neque quis dui tincidunt mattis eget sed dui. Cras egestas ante ante. Vestibulum vulputate pretium condimentum. Pellentesque a placerat nunc. Donec in urna ac mauris tristique mattis sit amet ut ex. Nullam ac sapien nisi. Donec vitae eros faucibus, imperdiet erat eu, tincidunt velit. Etiam gravida velit id volutpat tempus. Nunc odio odio, tincidunt et mi sit amet, aliquam lobortis tortor. Donec finibus libero vel risus luctus dictum. Pellentesque tristique nunc rhoncus magna scelerisque, sit amet gravida urna laoreet. Vestibulum nec orci ac lorem volutpat rutrum.
</div>
<div class="footer">
<div class="dummyContains"></div>
</div>
</div>

Divs take up all available height

I want to create three divs inside of one 'wrapper'-div. I want the three divs, let's call them 'left', 'center' and 'right', to be visible like three columns next to each other. The columns are shown in the right way, and the height takes up 100% of the screen, but when I add more text in the center div, I want the divs to take all available height of the screen. Like you see in the snippet below, the heights of the divs won't vertically stretch like I'd want them too.
I tried changing the divs to table and table-cell display, but I couldn't get this to work. Besides that I tried messing around with position absolute and relative, but I couldn't get this to work either.
In the real situation the centered div takes up 1024px in width and the left and right divs have a width of 50%-512px.
I searching for a way to solve this but I still couldn't get it to work.
html, body{
margin: 0;
padding: 0;
height: 400px;
}
div#menu{
height: 30px;
background-color: green;
width: 600px;
}
div#wrapper{
height: 100%;
width: 100%;
}
div#left{
background-color: yellow;
float: left;
width: 100px;
height: 100%;
}
div#center{
width: 400px;
background-color: red;
height: 100%;
float: left;
}
div#right{
width: 100px;
float: left;
height: 100%;
background-color: blue;
}
<html>
<body>
<div id="menu">
menu-item 1, menu-item 2, menu-item 3
</div>
<div id="wrapper">
<div id="left">
</div>
<div id="center">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi eleifend tellus eget odio cursus, id dignissim dolor tincidunt. Maecenas libero quam, scelerisque tincidunt est sit amet, consequat faucibus massa. Fusce at varius nunc. Integer mattis velit purus, nec dignissim ipsum pulvinar eget. Nulla facilisi. Suspendisse tempor, turpis eu convallis commodo, erat elit cursus sem, vel dignissim augue urna sit amet purus. Fusce accumsan risus neque, a dapibus velit mollis in. Aliquam varius euismod lorem sit amet bibendum. Donec tempus neque ac interdum pulvinar.
Nulla id iaculis magna. Ut dui lorem, porttitor eget volutpat vel, interdum at nibh. Duis rhoncus, eros ut pharetra euismod, metus metus elementum enim, id egestas sem arcu sit amet nisl. Quisque sed aliquam est. Vivamus bibendum sapien sit amet nisi auctor, et congue elit cursus. Praesent feugiat ex ex, in elementum augue efficitur a. Sed a felis ut est pharetra venenatis eu ac metus. Donec sed nisl semper, dignissim est ac, faucibus dolor. Interdum et malesuada fames ac ante ipsum primis in faucibus. Cras bibendum nulla dolor, et tincidunt ligula hendrerit ac.
Integer et tincidunt ante, tincidunt hendrerit lacus. Nullam viverra id enim et viverra. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean ullamcorper posuere pharetra. Nullam ac quam eu nisl vulputate condimentum quis eu ante. Mauris vel egestas tortor. Ut suscipit ex ac commodo pharetra. Sed pharetra convallis ornare. Curabitur posuere dictum sapien, et rutrum nulla tempor sit amet. Nulla sagittis massa quis vulputate vehicula. Proin dignissim lorem vel neque finibus, ut sodales dolor sollicitudin. Maecenas finibus leo non lorem porttitor condimentum. Aenean nec odio id nulla scelerisque bibendum.
Fusce feugiat sem turpis, id iaculis dui condimentum vel. Vivamus tempus semper ultricies. Vestibulum egestas viverra blandit. Nunc leo justo, semper ut elit in, luctus pharetra nibh. Cras ac lectus egestas quam interdum vehicula. Vivamus pulvinar sapien sed gravida pharetra. Mauris hendrerit congue augue, quis vulputate mauris vulputate at. Nulla sit amet ullamcorper ante.
In lobortis sem id arcu dignissim pretium. Sed vulputate eleifend leo. Donec eget risus sit amet ante molestie porta. Phasellus massa diam, lacinia ac imperdiet ut, molestie vitae nisl. Pellentesque tristique ligula lacus, eu tempus est feugiat vitae. Ut ac tincidunt nunc. Nulla et lectus quam. Aenean auctor tempus nibh sed efficitur. Nam blandit dictum ligula bibendum mollis. Proin mollis lorem at viverra porttitor. Duis placerat bibendum libero, id vulputate quam posuere id. Vestibulum vel ex mollis, tempor tortor et, suscipit risus. In augue dui, bibendum et tempus id, hendrerit vitae sapien. Aliquam erat volutpat.
</div>
<div id="right">
</div>
</div>
</body>
</html>
Have you tried using flexbox? You could make them all the same height using something like this:
#wrapper{
display: flex;
flex-direction: row;
}
#left, #center, #right {
display: flex;
}
https://jsfiddle.net/rxdd4mdd/
Update:
I had a look at the website you posted a link to and you need to replace the folowing rules in your css, with these:
#profile-wrapper {
display: flex;
flex-direction: row;
width: 100%;
}
#profile-wrapper .left,
#profile-wrapper .right {
background-color: #ebebeb;
display: flex;
flex: 1;
}
#profile-wrapper #profile-page {
width: 1024px;
display: flex;
flex-direction: column;
}
I've posted the full HTML of the edited page here: http://pastebin.com/9PvQvfiU
Update 2:
This should make sure that it is at least 100% of the height of the body:
body {
display: flex;
flex-direction: column;
}
#profile-page {
flex: 1;
}
Use Style Height :Auto; for wrapper div
#wrapper {
width: 600px;
height: auto;
}
https://jsfiddle.net/kn9spjhn/

How do I keep my footer div from overlapping with my page content?

I used this code to print a table using JSTL. The table was in the contentFrame div. However, the footer which was initially at the bottom started to float and overlap with the contentFrame. I don't want to keep the footer in a fixed position though. Is there a way to keep it at the bottom of the page such that when new content is added it is "pushed" down?
body {
background-color: blue;
}
#contentFrame {} #date {
float: left;
}
#logOutFrame,
#contentFrame,
#headerFrame,
#menuFrame {
background-color: red;
}
#headerFrame {
margin-top: 30px;
}
#logOutFrame {
left: 0px;
position: absolute;
text-align: right;
top: 0px;
width: 100%;
}
#footerFrame {
background-color: orange;
bottom: 0px;
left: 0px;
position: absolute;
text-align: center;
width: 100%;
}
<div id="logoutFrame">
<span id="date"> Date </span>
<span id="userEmail"> blah#email.com </span>
<a id="signOutLink" href="#"> Sign Out </a>
</div>
<div id="headerFrame">
<h1>Pointwest Logo</h1>
</div>
<div id="menuFrame">
<ul>
<li>A</li>
<li>B</li>
</ul>
</div>
<div id="contentFrame">
// content
</div>
<div id="footerFrame">
<p>footer</p>
</div>
EDIT: used the sticky footer from bootstrap and it worked
One way to solve this is:
Give the #footerFrame a default position: absolute
Use .js to monitor the height of the browser viewport and the height of the #contentframe
If #contentframe height exceeds the remaining viewport height, change #footerFrame to position: relative
function positionFooter() {
var contentFrame = document.getElementById('contentFrame');
var footerFrame = document.getElementById('footerFrame');
var contentY = contentFrame.offsetTop;
var contentHeight = contentFrame.clientHeight;
var viewportHeight = window.innerHeight;
var footerHeight = footerFrame.clientHeight;
if ((contentY + contentHeight) > (viewportHeight - footerHeight)) {
footerFrame.style.position = 'relative';
}
else {
footerFrame.style.position = 'absolute';
}
}
window.addEventListener('load',positionFooter,false);
window.addEventListener('resize',positionFooter,false);
body {
background-color: blue;
}
#contentFrame {
height: 300px;
}
#date {
float: left;
}
#logOutFrame,
#contentFrame,
#headerFrame,
#menuFrame {
background-color: red;
}
#headerFrame {
margin-top: 30px;
}
#logOutFrame {
left: 0px;
position: absolute;
text-align: right;
top: 0px;
width: 100%;
}
#footerFrame {
display: block;
position: absolute;
bottom: 0px;
left: 0px;
width: 100%;
height: 50px;
background-color: orange;
text-align: center;
}
body, #contentFrame, #footerFrame, #footerFrame p {
margin: 0;
padding: 0;
}
<div id="logoutFrame">
<span id="date"> Date </span>
<span id="userEmail"> blah#pointwestcom.ph </span>
<a id="signOutLink" href="#"> Sign Out </a>
</div>
<div id="headerFrame">
<h1>Pointwest Logo</h1>
</div>
<div id="menuFrame">
<ul>
<li>A</li>
<li>B</li>
</ul>
</div>
<div id="contentFrame">
// content
</div>
<div id="footerFrame">
<p>footer</p>
</div>
You should use <div style="clear:both;"></div> to clear float before footer this way:
<div style="clear:both;"></div>
<div id="footerFrame">
<p>footer</p>
</div>
but no need to make position of footerFrame absolute:
#footerFrame {
background-color: orange;
text-align: center;
width: 100%;
}
and TO LEARN MORE ABOUT FLOATS check this out:
https://css-tricks.com/all-about-floats/
How big is your content?
If you remove the 'position: absolute;' or 'bottom: 0px;' from the #footerFrame css, the footer will move up to position itself under the page content.
If your content isn't big enough to fill the window, this may not be desired.
There is a number of footer solutions already on SO if you search for them that will show you the many ways you can achieve a footer solution that will work for you.
EDIT NOTE: this answers a different question, as I thought the header/footer needed to be in a fixed position. Left here for usefulness based on question title, but otherwise incorrect.
If you're able to accurately declare the height of your header and footer, this is exactly what position:fixed was made for.
NOTE: I only used [attribute] selectors for speed of creating the demo! Use classes instead in your actual production code- it's what classes are for, and doesn't run the risk of getting blasted by some shiny new feature at some point in the future!
http://dabblet.com/gist/a633128f55dbcc160ecc
[head]{
position:fixed;
width:100%;
top:0px;
height:20px;
background-color:#ccc;
}
[foot]{
width:100%;
position:fixed;
bottom:0px;
height:20px;
background-color:#ccc;
}
[cont]{
/*set the top margin to the height of the header, plus a bit of buffer*/
/*set the bottom margin to the height of the header, plus a bit of buffer*/
margin:25px 0 25px;
}
<div head>
This is a header
</div>
<div foot>
This is a footer
</div>
<div cont>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque lobortis dui eget ex ullamcorper, id hendrerit lectus semper. Etiam aliquam lacus posuere, tempus quam et, tempus sapien. Sed vitae lobortis urna. Nulla at augue libero. Morbi cursus quam non velit commodo tincidunt. Nulla facilisi. Quisque vitae ante a massa scelerisque accumsan vitae in nibh. Mauris quam augue, gravida et rutrum sit amet, sodales et neque. Proin ullamcorper vulputate mi, ut suscipit nisi pharetra at. Aenean nibh orci, auctor id ex eu, molestie tincidunt velit. Praesent pretium ipsum finibus tortor pretium mollis. In et quam sodales, fermentum metus eget, volutpat lectus. Cras suscipit ipsum ut lectus placerat, vitae eleifend turpis varius. In consectetur nisl semper, maximus urna at, laoreet diam. Sed efficitur eleifend lectus, venenatis sollicitudin eros auctor nec.</p>
<p>Nunc egestas non diam id lobortis. Phasellus rhoncus, turpis interdum fermentum aliquet, risus enim commodo turpis, ac vestibulum massa neque vitae leo. Praesent non consequat leo, nec dignissim eros. Nullam convallis posuere ligula, eu tincidunt eros posuere vitae. Suspendisse vel fringilla metus, sit amet pellentesque justo. Donec feugiat elit in laoreet sagittis. Duis eget metus tellus. Suspendisse sollicitudin commodo dolor consequat efficitur. Nulla molestie leo at velit sagittis, vitae dictum eros gravida. Sed fringilla egestas ipsum, nec vulputate metus ornare in. Aenean et magna quis ante sodales posuere a pharetra purus. Sed malesuada nulla vitae eros lobortis, quis molestie lacus aliquam. Suspendisse eget arcu eu ex sollicitudin tempor ut eu ante. Aliquam mollis velit non elementum malesuada. Curabitur vehicula eu tellus sed tincidunt. Donec consequat neque id sapien venenatis, eget accumsan enim lacinia.</p>
<p>Nunc pellentesque nibh vitae quam aliquam pulvinar. Curabitur viverra odio quis purus commodo, in consequat nisi interdum. Morbi bibendum metus a mauris mattis, et laoreet erat eleifend. Morbi venenatis dapibus lorem, vitae egestas odio varius ac. Praesent id scelerisque ligula. Nullam dictum, metus sed fringilla sagittis, lacus magna bibendum metus, eget maximus ligula purus ac lectus. Vestibulum auctor sodales odio, ac gravida mauris pharetra quis. Etiam tincidunt pharetra lectus, ornare tempor augue ultricies in. Nulla tincidunt tempor eros. Aliquam ornare lorem dui, non pharetra orci elementum vitae. Nunc viverra consectetur orci, id dictum quam sodales a. Nullam vulputate orci nec luctus scelerisque. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In at facilisis augue. Aenean ullamcorper ex a enim lacinia suscipit.</p>
<p>Phasellus condimentum risus ut rutrum dapibus. Phasellus nec porta orci. Pellentesque laoreet odio at elementum tincidunt. Sed venenatis dui libero, quis fermentum nibh euismod quis. Proin sit amet tellus lorem. Ut egestas enim nec est sollicitudin pellentesque. Donec consequat luctus mi at mattis. Praesent pharetra mattis dolor non aliquam.</p>
<p>Phasellus libero eros, venenatis quis rutrum posuere, feugiat ac tellus. Phasellus et dolor nibh. Proin in erat mauris. Sed dictum mi sit amet tellus iaculis vulputate ut quis ex. Integer facilisis sed ante a euismod. Pellentesque sem felis, venenatis sit amet est id, cursus facilisis felis. Morbi commodo risus lectus, ac scelerisque velit iaculis ac. Nunc dignissim est nec lorem maximus, sit amet consectetur leo efficitur. Morbi sit amet diam augue. Ut nec magna a sapien dictum dapibus. </p>
</div>
If you're unable to declare the heights, well... you can fake it by including an exact copy of your header and footer without the position:fixed; but with visibility:none; above and below your content (respectively). Note that depending on how you do this, why the size is non-declarable, and what your header/footer contains, this may or may not be viable.
A less hacky way would be to add the margins with js based on the display size of your header/footer. I would actually suggest doing this instead, so long as the target browsers can support it.
If you want the footer to only marry the bottom if the content goes past it, you'll have to use js to detect the window size and default the footer/header to relative. If the window overflows, switch to fixed.