increase div as content in it increases - css

I have my HTML structure like this:
<div id="pagewrap">
<div id="header">
</div>
<div id="content">
<div id="left"></div>
<div id="right"></div>
</div>
<div id="footer"></div>
</div>
I want to increase size of content div when either divs in content div increases as same size as other div.
How can I achieve this?
This is how my css is:
#pagewrap
{
width: 100%;
height: 100%;
}
#header{width: 100%;height:97px;position:relative;}
#left{position:absolute;left:0px;width:20%;background-color:#1C2326;}
#right{position:absolute;right:0px;width:80%;background-color:#2D3538;color:#fff;}
#footer{clear:both;height: 80px;background-color:#72D27C;}

If you want the wrapper to be affected by the contents' dimensions, you can't use position: absolute in the inner divs. Try floating them instead (and add overflow: hidden to the container to clear the inner floats):
#pagewrap { width: 100%; height: 100%; }
#content { overflow: hidden; }
#header { width: 100%; height: 97px; position:relative; }
#left { float: left; width: 20%; background-color: #1C2326; }
#right { float: left; width: 80%; background-color: #2D3538; color: #fff; }
#footer { height: 80px; background-color: #72D27C; }
http://jsfiddle.net/h4hbx/

I think maybe this fiddle is closer to what you had in mind. You can let the left div (static position, no float) set the height of content, and then pin the top and bottom of the right div to the content div. As left grows, content grows, and right is tied to content, giving you the effect you want. However, this is asymmetrical -- if you want either div to cause the other to follow it, that's another problem.
CSS:
html, body {
height: 100%;
}
#pagewrap {
width: 100%;
height: 100%;
}
#content {
position: relative;
}
#header {
width: 100%;
height:97px;
}
#left {
left:0px;
width:20%;
background-color:#1C2326;
color: #fff;
top: 0;
}
#right {
position:absolute;
right:0px;
width:80%;
background-color:#2D3538;
color:#fff;
bottom: 0;
top: 0;
}
#footer {
clear:both;
height: 80px;
background-color:#72D27C;
}

Related

CSS - How to set a nested div against body bottom? (Image included)

How can I achieve the styling shown in the picture? Consindering the following scenario: I got 2 nested div elements, by which the parent is "relative positioned" and the child is "absolute positioned"! And the child div is always "fixed to the bottom" of the body element, when browser is scaled. I don't get this to work...
Here is the code, where I am using padding-bottom: 100%. But this is not a good solution! Is there a way to realise this with only CSS 2.1 API?
body {
min-height: 100%;
background-color: grey;
}
.parent {
height: 70px;
width: 440px;
left:200px;
background-color: blue;
position: relative;
}
.child {
display: block;
position: absolute;
width: 100px;
right:0px;
background-color: yellow;
padding-bottom: 100%;
}
<body>
<div class="parent">
<div class="child">Fix to bottom</div>
</div>
</body>
Don't take 2nd div as child. You want it to stick to bottom and parent div's height will disturb it while scalling.
I hope this helps :)
body {
min-height: 100%;
background-color: grey;
}
.parent {
height: 70px;
width: 400px;
left:100px;
background-color: blue;
position: relative;
top:70px;
}
.another-parent {
display: block;
height:60%;
position: absolute;
bottom:0;
width: 100px;
right:22%;
background-color: yellow;
}
<body>
<div class="parent"></div>
<div class="another-parent">Fix to bottom</div>
</body>

How to set two floated divs to be the 100% height of the page

There are two floated divs of different height inside a wrapper div. I need both of them to be 100% of height of the body i.e. of the same height. Also used clearfix. But height:100% doesnt seem to work. How to do this?
Demo
Html:
<div class="wrapper">
<div class="primary">
<img src="http://demo1.opentaps.org/images/products/small/gis_computer_glen_rolla.png" />
</div>
<div class="secondary">
<img src="http://demo1.opentaps.org/images/products/small/gis_computer_glen_rolla.png" />
</div>
<div class="clearfix">
</div>
</div>
CSS:
body {
min-height: 100vh;
background-color: green;
margin: 0;
}
.wrapper{
background-color: blue;
height: 100%;
}
.primary{
float: left;
width: 80%;
height: 100%;
background-color: yellow;
}
.primary img{
height: 100px;
width: 100px;
}
.secondary{
float: right;
width: 20%;
background-color: red;
height: 100%;
}
.secondary img{
height: 500px;
width: 100px;
}
.clearfix{
clear: both;
}
All you need to do is add a height of 100% to the html and body tags like so:
html, body {
height: 100%;
}
Demo:
http://jsbin.com/EsOfABAL/1/
if you want to use vh units (seen in your code), it does makes it easier, no need to worry about 'heritage' and see your columns being stopped at 100% height of the window.
if you mix the method of faux-column and clear fix , you need to set only once min-height:100vh; on the floatting element.
Your yellow background has to be drawn in the wrapper and the red one in the non-floatting element wich is stretch with the clearfix method.
body {
margin: 0;
}
.wrapper{
background-color: yellow;
overflow:hidden;
}
.primary{
float: left;
width: 80%;
min-height:100vh;
}
.wrapper .primary img{
height: 100px;
/* width:1000px; */
width: 100px;
}
.secondary .overflow{
margin-left:80%;
background-color: red;
}
.overflow:after {
content:'';
height:0;
display:block;
clear:both;
}
.secondary img{
height: 500px;
/*height:100px;*/
width: 100px;
}
uncomment height value for image to check behavior and drawing of your page, scrolling or not .
http://codepen.io/anon/pen/chHtK
Hope this helps you to understand the use of vh (or vw) units , for the faux-column and clearfix methods, it's just a reminder of old methods :)
Enjoy
The html element also needs to be 100% - try this:
html { height: 100%; }
body {
height: 100%;
background-color: green;
margin: 0;
}

How to make side-by-side blocks fill the rest of the container when one is fixed size?

I have two blocks that are side-by-side. One size is fixed, 90px and other one is not, I want the other one to extend itself to the rest of the container since container size is will be changing.
Here is fiddle with commends displaying the problem: http://jsfiddle.net/L6CSG/
HTML
<div class="container">
<span class="left"></span>
<span class="right"></span>
</div>
CSS
.left, .right {
height: 30px;
display: inline-block;
margin: 0px;
float: left;
}
.left {
background: green;
width: 90px;
}
.right {
background: blue;
width: 100%; // How can I make it fit the rest of the container?
}
.container {
width: 400px; // This value is NOT STATIC
}
You can do it by pure CSS, here is working example jsFiddle
Make sure filler element is last in DOM tree
Make sure rest of the elements have position: relative specified and width+height
This is nice trick I learned:
HTML:
<div id="container">
<div class="left"></div>
<div class="rest"></div>
</div>
CSS:
#container {
width:50%;
height: 50px;
background-color: red;
min-width: auto;
}
.left {
position: relative;
float: left;
width: 90px;
height: 100%;
background: blue;
}
.rest {
display: block;
height: 100%;
overflow: hidden;
background: yellow;
}
Solution 1:
Make the width of .right width: calc(100% - 90px);
Solution 2:
http://jsfiddle.net/L6CSG/4/ In case of this solution you should probably use divs instead of span since I changed your spans to block elements.
You have to set float: left only for the left one
see result:
http://jsfiddle.net/L6CSG/2/
also you need display: block and width: auto for the right one
Here is the solution:
HTML:
<div class="container">
<span class="left"></span>
<span class="right"></span>
</div>
CSS:
.left, .right {
height: 30px;
margin: 0px;
display: block;
}
.left {
background: green;
width: 90px;
float: left
}
.right {
background: blue;
width: auto;
}
.container {
width: 400px;
}
JavaScript is needed to calculate the extra space that can be filled, as the container is not a fixed width.
var con = document.querySelector(".container");
var left = document.querySelector(".left");
var right = document.querySelector(".right");
window.addEventListener('resize', function() {
calcSize();
});
function calcSize() {
var diff = con.offsetWidth - left.offsetWidth;
right.style.width = diff + "px";
}
calcSize();
http://jsfiddle.net/L6CSG/7/

How can I make the right column (<div>) take up the rest of the right space? (fiddle included)

I've run into a problem I have yet been unable to fix.
If you look at the following: http://jsfiddle.net/WnmLc/2/
<div id="top">top</div>
<div id="bottom">
<div id="left">left</div>
<div id="right">
<div id="head">head</div>
<div id="content">content</div>
<div id="footer">footer</div>
</div>
</div>​
This is what I got so far:
#top
{
height: 50px;
}
#bottom
{
position: absolute;
top: 50px;
bottom: 0;
}
#left
{
float: left;
height: 100%;
width: 100px;
}
#right
{
float: left;
height: 100%;
}
#content
{
height: 100%;
overflow: auto;
}
​
I'd like #right to take all the available space to its right, and footer to be within bounds of #right, which itself should not extend beyond #bottom. #content can be of any size and should just show a scrollbar when needed, #head and #footer should be at a fixed position, ie. top/bottom of #right.
I'm afraid I'm more fluent in javascript than I am at css, so I could use some pointers here :)
thanks in advance!
You can adjust the percentages of #left and #right. So long as they add up to 100%, this will work.
The same goes for #head, #content, and #footer. I assume you want the content to be larger, so I set that to 80% for you.
#bottom {
width: 100%;
}
#left {
width: 20%;
}
#right {
width: 80%;
}
#head, #footer {
height: 10%;
}
#content {
height: 80%;
}
See the fiddle here: http://jsfiddle.net/WnmLc/4/
EDIT:
If you want to set a manual width for #left, you could fix this by making #bottom a table, and both #left and #right table cells. Then you need to wrap #right in an outer div (table) so that the content inside can be displayed as table rows. #top will have to be moved into #bottom in order to avoid overflow.
However, I'd advise against using tables... They're outdated and lack support in certain browsers.
See fiddle: http://jsfiddle.net/WnmLc/8/
Hi i used this code on fiddle u can also try it there
div
{
border: 1px solid red;
}
#top
{
height: 50px;
}
#bottom
{
position: absolute;
top: 50px;
width:100%;
bottom: 0;
}
#left
{
float: left;
height: 100%;
width: 10%;
}
#right
{
float: left;
width:89%;
height: 100%;
}
#content
{
height: 87%;
overflow: auto;
}
​
Even though the table option as suggested by Michelle worked fine in the fiddle, it turned out that there where some serious issues regarding column-span when data was entered in the #top section.
I managed to get it to work using css without table-style code, you can find an example here:
http://jsfiddle.net/WnmLc/11/
html:
<div id="top">top</div>
<div id="left">left</div>
<div id="head">head</div>
<div id="content">
<div id="scroll">content</div>
</div>
<div id="footer">footer</div>
css:
div
{
position: absolute;
box-shadow: inset 0 0px 3px red;
}
#top
{
left: 0;
top: 0;
right: 0;
height: 50pt;
}
#left
{
left: 0;
top: 50pt;
width: 100pt;
bottom: 0;
}
#head, #footer
{
height: 12pt;
}
#head
{
top: 50pt;
left: 100pt;
right: 0;
}
#footer
{
bottom: 0;
left: 100pt;
right: 0;
}
#content
{
top: 62pt;
left: 100pt;
right: 0;
bottom: 12pt;
}
#scroll
{
width: 100%;
height: 100%;
overflow: auto;
}
​

Docking DIV to the side of the screen

I am trying to create sidebar. Well, the design is supposed to be 3 divs. Header (Which is already done), Sidebar, and the main div.
The sidebar is intended to be on the left side on the screen, extending all the way down to the bottom (height:100%). The problem I am stuck at is that I am not able to make a 100% Div as its height only extends to the number of lines of text I have in the div.
Here is the CSS for the sidebar that I currently have:
#sidebar {
float: left;
margin-top:36px;
width: 300px;
height:100%;
background-color: #111211;
}
Here is the CSS code for the body that I currently have:
body {
margin:0;
padding:0px;
background-color:#87AFC7;
}
Here is the HTML code:
<body>
<div id="sidebar"> left-sidebar </div>
</body>
You need to set the height of the parent of the sidebar to 100%, and in turn the parent of that. Since the sidebar is an immediate child of the body element, just add this to your CSS:
html,body { height:100%; }
You may try something like;
CSS
#container {
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
}
#top, #left, #right {
position: absolute
}
#top {
top: 0;
width: 100%;
height: 50px;
background: #00b7f0
}
#left {
top: 50px;
width: 50px;
bottom: 0px;
background: #787878
}
#right {
top: 50px;
left: 50px;
right: 0;
bottom: 0px;
background: #ff7e00
}
HTML
<div id="container">
<div id="top"></div>
<div id="left"></div>
<div id="right"></div>
</div>
Here is a working Live Demo.
Hope this helps..
Please try this and let me know
#sidebar {
position:fixed;
right:0px;
margin-top:36px;
width: 300px;
height:100%;
background-color: #111211;
}
body, html {
hieght:100%
}
You can use pixels instead of percentages:
height:1000px;

Resources