What would be a good way of positioning two divs (green and yellow) inside a parent div (blue outline) so that it looks like in the second drawing below? (First drawing is how divs stack by default).
I have a number of these blue divs whose green divs are variable height (different amount of text) and the yellow divs are always the same.
I want the yellow divs to always be at the bottom of the container.
Edit: Forgot to mention that all my blue parent divs should be same height
I tried positioning yellow divs as position:absolute with bottom:0 and blue divs to position:relative but this didn't work because then if one of the green divs has a lot of text it will run into and text will overlap the yellow div;
Blue parent divs are set to height:100%
What am I missing here?
Sorry if newbie question, I'm just getting into CSS and UI design.
You can make use of the flexbox properties. I just set the height for snippet purpose. You can alter the height based on your preference and check the text.
.parent {
display: flex; /* Activate Flexbox container */
flex-direction: column; /* To set the main axis in block direction */
justify-content: space-between; /* Align them distributed equally from first to last */
height: 150px;
width: 200px;
border: 5px solid #00A2E8;
}
.child1 {
background: green;
height: 25%;
}
.child2 {
background: yellow;
height: 25%;
}
<div class="parent">
<div class="child1"></div>
<div class="child2"></div>
</div>
Assuming the yellow div is a fixed height this is pretty easy
.parent {
/*Children will be positioned relative to this*/
position: relative;
/*Allow to be > 100% if content requies it*/
/*154 = height of yellow div + border*/
min-height: calc(100vh - 154px);
/*Height of yellow div*/
padding-bottom: 150px;
border: 2px solid blue;
/*The following is purely for demo purposes*/
width: 25%;
display: inline-block;
vertical-align: top;
}
/*The Green div is pretty standard*/
.green {
background-color: green;
color: white;
}
.yellow {
background-color: yellow;
/*Fixed height*/
height: 150px;
/*Set to postion absolute - relative to parent*/
position: absolute;
/*Set bottom to bottom of parent*/
bottom: 0;
/*Giv it a width*/
width: 100%
}
/*Tweak margins for first and last paragrpahs*/
.green p:first-of-type {
margin-top: 0;
}
.green p:last-of-type {
margin-bottom: 0;
}
body {
margin: 0
}
<div class="parent">
<div class="green">
<p>Some text</p>
</div>
<div class="yellow">
</div>
</div>
<div class="parent">
<div class="green">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque nibh justo, tincidunt sed elementum id, dictum quis nunc. Pellentesque et sodales mi.
</p>
</div>
<div class="yellow">
</div>
</div>
<div class="parent">
<div class="green">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque nibh justo, tincidunt sed elementum id, dictum quis nunc. Pellentesque et sodales mi. Mauris luctus leo ac eros tempor, quis gravida leo pellentesque. Etiam odio nisl, lobortis ut elit
ut, mollis eleifend ex. Etiam et risus at diam iaculis sagittis. Pellentesque porttitor odio suscipit, fringilla odio et, laoreet lectus. Nunc tincidunt ultrices condimentum. Nulla sit amet ante posuere, convallis justo vitae, facilisis orci. In
congue egestas diam vitae fermentum. Vivamus efficitur ligula sed tincidunt blandit. Etiam feugiat egestas sem ut pellentesque. Nulla ac dui bibendum, finibus mi vitae, suscipit quam.
</p>
<p>
Etiam pellentesque, diam eget condimentum rutrum, odio orci ultrices eros, in tincidunt magna tortor id augue. Nunc vitae dolor a risus egestas hendrerit a et augue. Pellentesque rhoncus lacus elit, at laoreet dolor pretium condimentum. Sed egestas placerat
ante, in convallis arcu facilisis id. Sed nec rutrum velit. Fusce eget sem turpis. Nulla facilisi. Nam suscipit ante leo, non viverra mauris ultrices id. Donec dui ligula, aliquet sed risus vitae, mollis posuere est. Aenean elementum, libero quis
fermentum dictum, sem lacus volutpat orci, quis rutrum ante odio eleifend risus. Nullam placerat et lacus in sagittis. Suspendisse potenti. Maecenas ullamcorper cursus ligula sit amet ullamcorper.
</p>
</div>
<div class="yellow">
</div>
</div>
If you use flex this will be supereasy -:
.container {
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
height: 500px;
border: 2px solid blue;
}
.green {
flex: 1;
width: 100%;
background: green;
}
.white {
flex: 1;
width: 100%;
background: white;
}
.yellow {
flex: 1;
width: 100%;
background: blue;
}
<div class="container">
<div class="green"></div>
<div class="white"></div>
<div class="yellow"></div>
</div>
In this case we have given flex: 1 for all the divs, so the ratio
of all the 3 divs is 1:1:1.
If you give the value of flex to be 1,2,1 then the ratio will be
1:2:1 i.e. 25%,50%,25% of the total height of container.
Also we need to define height for outer div so that ratio distribution can happen.
Related
I have an image and content side by side with the image positioned absolute to the left edge of the viewport and then a column of content. When I resize the browser, the image stays in place and eventually covers the content.
Is it possible to force the image to "push" to the right so that it moves left, out of the viewport as I resize? I can't change the HTML so I am forced to use the existing code.
.container {
max-width: 1230px;
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
.content-wrap {
padding-left: 250px;
}
.floating-image {
position: absolute;
top: 50%;
left: 0;
width: 50%;
transform: translateY(-50%);
max-width: 350px;
}
.floating-image img {
max-width: 100%;
height: auto;
}
<div class="container">
<div id="" class="row-wrapper">
<div class="content-wrap ">
<h2>ABOUT US</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque accumsan porta ultrices. Quisque tincidunt felis tellus, vel pharetra nisi condimentum vitae. Etiam mollis scelerisque leo, sed posuere tortor vulputate ut. Aliquam sed nisi id tortor euismod volutpat. Praesent laoreet dictum elit. Donec placerat blandit eleifend. Pellentesque molestie metus mi. Nullam eleifend venenatis imperdiet. Suspendisse egestas lorem eu turpis sollicitudin hendrerit. Aenean ultricies ultrices tortor, at efficitur mi dapibus eu. Donec ut pharetra sapien.</p>
</p>
</div>
<div class="alignment-wrap text-left">
<div class="img-wrap floating-image">
<img src="https://via.placeholder.com/750">
</div>
</div>
</div>
</div>
You can use media queries to hide the image when the size of the window is below specified length.
So maybe try something like this:
#media (max-width: [desired width]px) {
.floating-image img {
display: none;
}
}
I have a CSS issue which perhaps is too specific for this forum but I think maybe other people will benefit from it as well.
I have an element which has a max-height set, inside it there are two additional elements like so:
Code example:
<div class="container">
<div class="inner-element">...</div>
<div class="inner-element">...</div>
</div>
The the content of the two inner element has unknown height, which can be changed in runtime. I want the following behavior:
If the sum of the contents are less than max-height, they should each have their content's height, and the outer element should not be higher then their content:
If the sum of contents is more than max-height and both are more than half of it, each should get half the max-height:
If the sum of contents is more than max-height but one of the elements' content is less then 50%, the smaller one should have its content's height, and the bigger one should fill the remaining space:
I feel like that should be possible with pure CSS but I couldn't figure out a way to do it. Anyone has any idea?...
If you do not specify height on container then it's initial value is auto. Auto means it's height is determined by it's children. So height will always be equal to it's content height.
max-height is not same as height, it is applied after height is calculated ref. Setting max-height doesn't mean you are setting height also. You are just clipping the element height.
Your case 2 and 3 demands children to be dependent on parent containers height. But the container's height is dependent on the children. That is why you'll need javascript to implement case 2 and 3.
In case if you decide to have fixed height to the container then you can use grid with auto-fit templet-rows to achieve all the test cases using pure CSS:
//the script is used only for increasing content heights for the demo
var c1, c2;
var r1, r2;
document.addEventListener('DOMContentLoaded', init);
function init() {
c1 = document.getElementById('c1');
c2 = document.getElementById('c2');
r1 = document.getElementById('r1');
r2 = document.getElementById('r2');
r1.addEventListener('change', update1);
r2.addEventListener('change', update2);
update1();
update2();
}
function update1() {
c1.style.height = r1.value + 'px';
c1.innerText = 'Content Height: ' + r1.value + 'px';
}
function update2() {
c2.style.height = r2.value + 'px';
c2.innerText = 'Content Height: ' + r2.value + 'px';
}
* {
box-sizing: border-box;
}
.container {
height: 200px;
border: 2px solid;
background-color: lemonchiffon;
display: grid;
grid-template-rows: repeat(auto-fit, minmax(0, min-content));
}
.container>div {
border: 1px dashed gray;
overflow: auto;
height: fit-content;
max-height: 100%;
}
.inner-element:nth-child(1) {
background: lightgreen;
}
.inner-element:nth-child(2) {
background: lightblue;
}
<div>
<label for="r1">Element one height: 0</label>
<input type="range" id="r1" name="r1" min="0" max="400" value="50">400
</div>
<div>
<label for="height2">Element two height: 0</label>
<input type="range" id="r2" name="r2" min="0" max="400" value="50">400
</div>
<div class="container">
<div class="inner-element">
<div id=c1></div>
</div>
<div class="inner-element">
<div id=c2></div>
</div>
</div>
You do not need to put max-height on any of the children.
Just put a max-height on the parent, then the flexbox will do the rest !
.grid {
--gutterH : 30px;
--gutterV : 30px;
display: flex;
flex-wrap: wrap;
flex-grow: 1;
width: calc(100% + var(--gutterV));
margin: calc(var(--gutterH) / -2) calc(var(--gutterV) / -2);
}
.grid-item {
--gridItemWidth : auto;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
align-content: flex-start;
margin: calc(var(--gutterH) / 2) calc(var(--gutterV) / 2);
width: calc(var(--gridItemWidth) - var(--gutterV));
}
.grid-item.grid-item--onethird {
--gridItemWidth : calc(100% / 3);
}
.container {
display: flex;
flex-direction: column;
width: 100%;
max-height: 250px;
border: solid 1px #000;
}
.inner-element {
display: flex;
justify-content: center;
align-items: center;
padding: 15px;
overflow: hidden;
}
.inner-element:not(:last-child) {
border-bottom: solid 1px #000;
}
<div class="grid">
<div class="grid-item grid-item--onethird">
<!-- Case 1 -->
<div class="container">
<div class="inner-element">
1
</div>
<div class="inner-element">
2
</div>
</div>
</div>
<div class="grid-item grid-item--onethird">
<!-- Case 2 -->
<div class="container">
<div class="inner-element">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut risus dapibus purus blandit tristique non vel purus. Nam bibendum elementum justo, rutrum tristique massa faucibus id. Integer ut metus justo. Etiam vitae congue risus. Nulla quis libero vel est fermentum efficitur. Cras mollis aliquet metus id rhoncus. Proin gravida, leo quis rhoncus lacinia, erat nulla consequat magna, at elementum dui tellus facilisis leo. Ut nec ex eleifend, scelerisque lorem nec, bibendum quam. Fusce quis sapien ut sapien lacinia congue.
</div>
<div class="inner-element">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut risus dapibus purus blandit tristique non vel purus. Nam bibendum elementum justo, rutrum tristique massa faucibus id. Integer ut metus justo. Etiam vitae congue risus. Nulla quis libero vel est fermentum efficitur. Cras mollis aliquet metus id rhoncus. Proin gravida, leo quis rhoncus lacinia, erat nulla consequat magna, at elementum dui tellus facilisis leo. Ut nec ex eleifend, scelerisque lorem nec, bibendum quam. Fusce quis sapien ut sapien lacinia congue.
</div>
</div>
</div>
<div class="grid-item grid-item--onethird">
<!-- Case 3 -->
<div class="container">
<div class="inner-element">
1
</div>
<div class="inner-element">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut risus dapibus purus blandit tristique non vel purus. Nam bibendum elementum justo, rutrum tristique massa faucibus id. Integer ut metus justo. Etiam vitae congue risus. Nulla quis libero vel est fermentum efficitur. Cras mollis aliquet metus id rhoncus. Proin gravida, leo quis rhoncus lacinia, erat nulla consequat magna, at elementum dui tellus facilisis leo. Ut nec ex eleifend, scelerisque lorem nec, bibendum quam. Fusce quis sapien ut sapien lacinia congue.
</div>
</div>
</div>
</div>
Here you go, a flexbox is perfect for this case:
You can give the children also a max-height.
The problem with that is that they cant be bigger of that value, if there is still space in the parent div.
If you dont have max-height in the children they will fill all the available space if needed. But now you have the problem that if both if taller then half of the space, they won't share the space 50/50. They will share it proportional of their height.
If you really really want the condition of the 2. behavior you mentiont in your question you need to use javascript.
-> You can add both height from the children and if they the total is bigger than the max-height you can set both to a spesific height.
#parent {
max-height: 180px;
width: 100px;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
}
.child {
background: yellow;
border: 2px solid black;
overflow-x: hidden;
padding: 5px;
}
<body>
<div id="parent">
<div id="a" class="child">
test<br>te<br>sttes<br>ttes<br>ttes<br>tte<br>sttes<br>t<br>t<br>es<br>t<br>t<br>e<br>stt<br>e<br>s<br>t
</div>
<div id="b" class="child">
t<br>e<br>s<br>t
</div>
</div>
</body>
How could I limit an image's maximum height so it would be the same as its sibling's height regardless of screen size.
The result which is acceptable =>
Same height - √
A result which isn't acceptable since image column height exceeds its sibling's => (DIV - .main-content).
Not valid one - X
P.S. Background-image property is not suitable in this case.
.container {
display: flex;
height: 100%;
}
.container>div {
flex: 1;
}
.main-content {
background: pink;
padding: 20px;
}
.sidebar img {
object-fit: cover;
width: 100%;
height: 100%;
}
<div class="container">
<div class="main-content">
Morbi mollis tellus ac sapien. Aenean vulputate eleifend tellus. Donec vitae orci sed dolor rutrum auctor. Cras non dolor. Vivamus quis mi. Vestibulum rutrum, mi nec elementum vehicula, eros quam gravida nisl, id fringilla neque ante vel mi. Aenean commodo
ligula eget dolor. Fusce neque. Quisque libero metus, condimentum nec, tempor a, commodo mollis, magna..
</div>
<div class="sidebar">
<img src="https://placeimg.com/640/490/nature">
</div>
</div>
Ok, it seem's that I might have found a solution. One way is to position the image as absolute and "stretch it" while object-fit still maintains it's cover property. If someone has some better solution, feel free to share.
.container {
display: flex;
height: 100%;
=
}
.container > div {
flex: 1;
}
.main-content {
background: pink;
padding: 20px;
}
.sidebar img {
object-fit: cover;
position: absolute;
top: 0;
bottom: 0;
right: 0;
overflow: auto;
height: 100%;
width: 100%;
}
.sidebar {
position: relative;
}
<div class="container">
<div class="main-content">
Morbi mollis tellus ac sapien. Aenean vulputate eleifend tellus. Donec vitae orci sed dolor rutrum auctor. Cras non dolor. Vivamus quis mi.
Vestibulum rutrum, mi nec elementum vehicula, eros quam gravida nisl, id fringilla neque ante vel mi. Aenean commodo ligula eget dolor. Fusce neque. Quisque libero metus, condimentum nec, tempor a, commodo mollis, magna..
</div>
<div class="sidebar">
<div><img src="https://placeimg.com/640/1000/nature"></div>
</div>
</div>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Basically I have 3 divs:
<div></div>
<div></div>
<div></div>
clicking on 1st div toggles visibility of 2nd div
what I want is that 3rd div would take up all the remaining space but no more. In case of large 3rd div content I want scrollbar only on 3rd div, not whole page.
I have JS solution. So any pure CSS would be highly appreciated.
Here is one approach that involves using a combination of CSS table-cells and absolute positioning.
Create a CSS table as the top level container .main, and define three display: table-row containers .head, .extra and .content.
Within .content, nest a display: table-cell element .wrap and set position: relative. Within .wrap, use absolute positioning to fit a .scroller container that will hold the content.
If you hide the .extra block, the .content will stretch vertically to take up the remaining space.
html, body {
height: 100%;
margin: 0;
}
.main {
border: 1px dotted gray;
width: 100%;
height: 100%;
box-sizing: border-box;
display: table;
overflow: hidden;
}
.head {
display: table-row;
height: 50px;
background-color: beige;
}
.extra {
display: table-row;
/* display: none; */
height: 100px;
background-color: tan;
}
.content {
display: table-row;
background-color: lightblue;
height: auto;
}
.content .wrap {
display: table-cell;
height: auto;
position: relative;
}
.scroller {
overflow: auto;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
<div class="main">
<div class="head">head</div>
<div class="extra">extra</div>
<div class="content"><div class="wrap"><div class="scroller">
<p>Scrolling div...</p>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque bibendum imperdiet metus ac elementum. Donec viverra porttitor velit, ut eleifend nulla porttitor quis. Donec placerat, leo ac volutpat pellentesque, elit mauris aliquet metus, sit amet dictum enim augue consequat elit. Pellentesque eu diam a sem ornare tristique. Sed sollicitudin elementum nibh, eget tincidunt sem rhoncus at. Morbi cursus ornare dolor, vel tempus leo blandit ut. Donec at dictum eros. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Integer faucibus tellus in aliquet accumsan. Nam scelerisque ante eros, et tempus dolor mollis nec. Cras in mauris ac orci hendrerit venenatis. Nunc porta nisi eu odio feugiat, sed fermentum odio posuere. Vivamus luctus dui sit amet lobortis dignissim. Nulla feugiat est lacinia est porta porttitor. </p>
</div>
</div>
</div>
</div>
If you know that there will only be three divs, you could just control the height and change it from 33% to 66% when the second div collapses, and using css transition to make the animation.
I'm trying to create a scroll bar inside the #main div so that I can scroll that without scrolling the page or the title but it isn't working. What am I missing?
My code is as follows:
CSS
#topbar {
height: 40px;
background-color: blue;
}
#sidebar {
position: absolute;
top: 40px;
bottom: 0px;
width: 80px;
overflow: hidden;
}
#title {
height:30px;
background-color: red;
}
#main {
height: auto;
overflow: scroll;
}
HTML
<div id="topbar">
hello
</div>
<div id="sidebar">
<div id="title">
title
</div>
<div id="main">
<!-- lots and lots of text-->
</div>
</div>
You can find an example JSFiddle here: http://jsfiddle.net/PTRCr/
Thanks
You're still on this project I see. There's also a lot of answers, but I see no one has made a working example of what I think you're asking for.
Here's a working example that (I hope) does what I think you're asking for.
I added content shifting wrappers so that the height can still be 100%. You can read more about that technique from this answer. I also removed all that absolute positioning, I see no reason why you should do that.
Each wrapper adjusts for the previous content, first the top bar with the height 40px and then the title with 30px.
This example should also follow your previous specifications, where the scrollbars will stay on the same baseline when resized.
As you can see, by the code below, it is possible to do a CSS only solution despite what others have lead you to believe. It just takes a bit of tricks from the bag of CSS holding.
Man, I'm such a dork.
Example | Code
HTML
<div id='container'>
<div id="top-bar">hello</div>
<div class="wrapper">
<div class="side-bar">
<div class="title">title</div>
<div class="content_wrapper">
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur gravida interdum dignissim. Aenean quis neque diam, ac vehicula turpis. Vestibulum lacinia libero sed massa fringilla tempor. Donec dictum metus ac justo congue lacinia sit amet quis nisi. Nam sed dolor vitae nisi venenatis imperdiet ut ullamcorper sem. Maecenas ut enim in massa ultricies lacinia quis nec lorem. Etiam vel lacus purus, a placerat lectus. Ut sed justo eros. Curabitur consequat nisi ut diam lacinia at posuere purus tristique. Quisque eu dapibus nunc.</div>
</div>
</div><div class="side-bar">
<div class="title">title</div>
<div class="content_wrapper">
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur gravida interdum dignissim. Aenean quis neque diam, ac vehicula turpis. Vestibulum lacinia libero sed massa fringilla tempor. Donec dictum metus ac justo congue lacinia sit amet quis nisi. Nam sed dolor vitae nisi venenatis imperdiet ut ullamcorper sem. Maecenas ut enim in massa ultricies lacinia quis nec lorem. Etiam vel lacus purus, a placerat lectus. Ut sed justo eros. Curabitur consequat nisi ut diam lacinia at posuere purus tristique. Quisque eu dapibus nunc.</div>
</div>
</div><div class="side-bar">
<div class="title">title</div>
<div class="content_wrapper">
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur gravida interdum dignissim. Aenean quis neque diam, ac vehicula turpis. Vestibulum lacinia libero sed massa fringilla tempor. Donec dictum metus ac justo congue lacinia sit amet quis nisi. Nam sed dolor vitae nisi venenatis imperdiet ut ullamcorper sem. Maecenas ut enim in massa ultricies lacinia quis nec lorem. Etiam vel lacus purus, a placerat lectus. Ut sed justo eros. Curabitur consequat nisi ut diam lacinia at posuere purus tristique. Quisque eu dapibus nunc.</div>
</div>
</div><div class="side-bar">
<div class="title">title</div>
<div class="content_wrapper">
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur gravida interdum dignissim. Aenean quis neque diam, ac vehicula turpis. Vestibulum lacinia libero sed massa fringilla tempor. Donec dictum metus ac justo congue lacinia sit amet quis nisi. Nam sed dolor vitae nisi venenatis imperdiet ut ullamcorper sem. Maecenas ut enim in massa ultricies lacinia quis nec lorem. Etiam vel lacus purus, a placerat lectus. Ut sed justo eros. Curabitur consequat nisi ut diam lacinia at posuere purus tristique. Quisque eu dapibus nunc.</div>
</div>
</div>
</div>
</div>
CSS
body, html{
height:100%;
width: 100%;
line-height: 100%;
margin: 0; /* Normalization */
padding: 0; /* Normalization */
}
div{
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
#container{
height:100%;
width: 100%;
text-align: center;
overflow: auto;
}
#top-bar{
height: 40px;
line-height: 40px;
border: 1px solid lightblue;
background: blue;
color: white;
text-align: center;
}
.side-bar {
width: 120px;
height: 100%;
text-align: center;
color: white;
border: 1px solid DarkOrchid;
display: inline-block;
vertical-align: top;
}
.title {
height:30px;
line-height: 30px;
border: 1px solid salmon;
background: red;
}
.wrapper{
margin-top: -40px;
padding-top: 40px;
height: 100%;
width: 100%;
white-space: nowrap;
}
.wrapper > div{
white-space: normal;
}
.content_wrapper{
margin-top: -30px;
padding-top: 30px;
height: 100%;
}
.content{
color: black;
height: 100%;
overflow: auto;
}
The element you want to be scrollable, should
Have height and width defined
have attribute overflow:auto
Example:
.scrollArea {
width: 275px;
height: 100px;
padding-left: 5px;
padding-right: 5px;
border-color: #6699CC;
border-width: 1px;
border-style: solid;
float: left;
overflow: auto;
}
CSS are stylesheet whose only purpose are to style document. They cannot investigate a pre-existing elements.
The only ways are whether the size of the div has to be fixed or you have to use some JavaScript to find out the exact height. The ways of which this can be done with CSS have already been presented by other users.
So, here is a way you can do using jQuery
$("#main").height($(document).innerHeight()-$("#title").outerHeight() - $("#topBar").outerHeight());
Demo
In your case change CSS:
#sidebar {
position: absolute;
top: 40px;
bottom: 40px;
width: 80px;
overflow: scroll;
}
You should define the height of the <div id="main" to show the scrollbar on it. whether you calculate it using javascript or jquery.
#topbar {
height: 40px;
background-color: blue;
}
#sidebar {
position:absolute;
top: 40px;
bottom: 40px;
width: auto;
height:200px;
overflow: hidden;
}
#title {
height:30px;
background-color: red;
}
#main {
height: 100px;
width: 100%;
overflow:auto;
}
Check this updated jsFiddle.
You need to set height for #main. It is working at http://jsfiddle.net/PTRCr/7/
#main {
height: 100px;
overflow-y: scroll;
}
It is only possible if you know the height of your #title, in either px or as a percentage of its parent container
#title set in px jsFiddle
#main {
position:absolute;
top:30px; /* set this to whatever you have set the height of #title to*/
bottom:0px;
overflow-y: scroll;
}
#title set as % jsFiddle - Tested in IE/FF/Chrome