CSS 100% - 200px? - css

I'm trying to use <div> objects and CSS to emulate the appearance of frames for a project that I'm working on. Using the following code I was able to properly stretch the list on the left with a border-right, padding, and (if I choose) a background using only one extra element:
HTML:
<div id="sidebar">
<div id="sidebar-content">
<!-- content goes here -->
</div>
</div>
<div id="content">
<!-- more content -->
</div>
CSS:
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#sidebar {
float: left;
height: 100%;
width: 200px;
overflow: auto;
border-right: solid 1px #000;
}
#sidebar-content {
margin: 10px;
padding: 0;
list-style: none;
}
#content {
position: relative;
float: left;
padding: 10px;
}
This worked well until I tried adding another element at the top of the content which stretched horizontally. Here's the current code:
HTML:
<div id="content">
<div id="criteria">
<!-- select boxes -->
</div>
<!-- other content -->
</div>
CSS:
#criteria {
position: absolute;
left: 0;
right: 0;
background: #FF9;
}
This picture shows the results
I tried adding the following rule:
#content {
width: 100%;
}
although this stretched the #content div to the width of the body element, not the body minus the sidebar - so the content appeared below the fold (and beneath the sidebar on the left)
How can I use CSS to stretch the criteria box to fill the content area horizontally?
EDIT -
I wanted to upload a picture of what happened after Karl's recommendation:
Remove the float: left from #content. If there is a floated element next to a normal block element, the block element will fill the remaining space. Also don't set the width attribute.
Here's what happened when float: left was removed
Close, however now the #criteria is stretching to cover up the sidebar. Other suggestions?

Remove the float: left from #content. If there is a floated element next to a normal block element, the block element will fill the remaining space. Also don't set the width attribute.
Edit:
To address the issue of #criteria which is absolutely-positioned forcing itself over to the left, you can add a left-margin to #content to account for the width of the sidebar, as Steven discovered.
As a random sidenote, this would also allow you to keep the content aligned in the case that the sidebar did not take 100% height like it does in Steven's example.

I've used something like this before to get a sidebar layout
sidebar css
    width: 200px;
    z-index:2;
    float: left;
content css
    margin-left: 200px;
    z-index: 1;
    width: 100%;
    padding-right: 2
You can use a similar technique to get a header <div> too.
I might not have got the css exactly correct, but the idea is to use a combination of margin, padding and z-index to get a frames-like effect.

One option would just to have the sidebar and content areas' width based on percentage... say 20% for the sidebar and 80% for the content. I've run into this problem before and just gone with that, but I didn't do too much research on it.

Related

CSS 100% div height with 960 grid

I have been banging my head against the wall trying to figure out this problem and I have looked high and low for the answer and came up with similar results.
Synopsis
The problem is that I am building a website using the 960 grid and have three columns that I want to stretch at 100% at all times. Here is a fiddle for your reference: http://jsfiddle.net/Uec7h/1/
Essentially the html is like so:
<div class="contentWrapper">
<div class="container_12">
<div class="grid_2 leftSide clearfix">
Left sidebar content.
</div>
<div class="grid_7 content">
Lots of content loaded from the server.
</div>
<div class="grid_3 rightSide">
Right sidebar content.
</div>
</div>
</div>
with the CSS being like
html, body {
height: 100%;
}
.content {
height: 100%;
}
.leftSide {
height: 100%;
background-color: #000000;
}
.rightSide {
height: 100%;
background-color: #000000;
}
.contentWrapper {
height: 100%;
}
The fiddle isn't completely accurate to what I am seeing on my local version, but it's close. Seems like the left and right sidebars do not want to expand to 100% no matter what I do.
What I've Tried
Most of the answers I have found on SO have suggested to put height: 100% on the html, body elements and everything should work out fine. Adding this attribute and giving both sidebars height: 100% did work a little bit, but if the content in the middle column gets too big, it stops at a certain point and won't continue to stretch.
I have tried adding the clearfix class that comes with the 960 grid but it didn't seem to help at all.
Question
How do I get the left and right side bars height in the fiddle to be 100% no matter what content is in the middle column?
If you add the following CSS to the sidebar elements it will fill the 100% of the height.
display:block;
height:auto;
position:absolute;
top:0px;
bottom:0px;
If you place the sidebar into a wrapper div with relative positioning, the content section will be again in it's right place...
I would also set padding and margin to 0 for the body.
EDIT:
If you add height: 100% to the .container_12 it will get a real height, and children elements can have a 100% height. Notice that the sidebars will be as height as the window itself, but your content at the middle can be taller than 100%... Fiddle
Dont know the 960 grid, the EDITED solution - using visibility: visible; -
HTML
<div id="box">
<div class="vision"> sdfsdfsd </div>
</div>
CSS
#box {
float: left;
border: 2px solid red;
}
.vision {
width: 300px;
height: 600px;
visibility: visible;
}

Twitter Bootstrap - 100% Height

I'm trying to design an Admin panel for my application using twitter-bootstrap framework but i cannot get my layout to work.
I was inspired by this design:
It would be a two column layout "Sidebar" and "Main content" but I can't get the 100% height to work. I managed to get 2 column layout with 100% width using this code:
HTML
<div class="container-fluid">
<div class="row-fluid">
<div class="span2 colorize-white">
<!--Sidebar content-->Sidebar
</div>
<div class="span10 colorize-white">
<!--Body content-->Main
</div>
</div>
</div>
CSS
/* Global */
html, body {
color: #6B787F;
padding: 0;
height: 100%;
background: #11161a;
font-family: 'PT Sans' !important;
}
.colorize-white {
background: #FFFFFF;
}
.no-margin {
margin: 0;
}
I'm half way there but there are two things I can't solve.
1) 100% Height
2) Getting rid of outer margins on second image
You can see that I have margin between browser border and Sidebar/Main elements and then margin between the two. I need to get rid of this if I add no-margin to all my elements in HTML i pasted including body tag i still don't get 100% height and i still cant get rid of margins between browser border and sidebar and main content while the margin space between Sidebar and Main content disappears.
I'm not so sure Bootstrap's grid model is what you're looking for here. You may instead be looking for absolute positioning. For example:
#sidebar, #content {
position: absolute;
top: 0;
bottom: 0;
}
#sidebar { left: 0; width: 10em; }
#content { left: 10em; right: 0; }
Try it out.
Here is an example that works for Bootstrap 3..
Make sure the HTML and body are both 100% height. Wrap the sidebar and content and then use position:absolute on the sidebar.
http://www.bootstrapzero.com/bootstrap-template/basis
Code: http://bootply.com/86704
I am not sure if this is what you are looking for, but here it goes.
just modified the CSS slightly. margin:0; to html, body tag.

Divide a div into four equal parts filling the viewport with a fixed nav bar

So I have a fluid layout with a fixed nav. I have: the fixed nav itself, and a div containing four other divs that Im looking to fill the space beneath the fixed nav completely. I cant seem to make this happen without having some kind of scrolling of either the nav or the divs.
The nav is set to position:fixed
The div containing the content div is set to position:absolute height:100% width:100%
The four content divs themselves are set to float:left height:50% width:50%
Im not even certain this can be handled with css alone, if it can that would be awesome, if not, ill entertain other possibilities. Any help, as always, is greatly appreciated.
Development area:
http://riverhousegolf.icwebdev.com
Maybe there is solution with CSS only, but here is jQuery solution. Content below menu will fill rest of space, without scroll bars.
HTML markup will be:
<div id="menu">SOMETHING IN MENU</div>
<div class="content">
<div class="part1"></div>
<div class="part2"></div>
<div class="part3"></div>
<div class="part4"></div>
</div>
CSS:
body,html{padding:0; margin:0;height:100%;width:100%;}
#menu {
position: fixed;
top: 0;
background: blue;
height: 50px;
width: 100%;
}
.part1 {
width:50%;
height: 50%;
float: left;
background: purple;
}
.part2 {
width:50%;
height: 50%;
float: left;
background: red;
}
.part3 {
width:50%;
height: 50%;
float: left;
background: green;
}
.part4 {
width:50%;
height: 50%;
float: left;
background: silver;
}
.content{
width: 100%;
position: relative;
}
jQuery:
var height = $(document).height();
var menu_height = $("#menu").height();
var content_height = height - menu_height;
$(".content").css("height", content_height);
$(".content").css("top", menu_height);
DEMO
Most important part is jQuery. First, we need to get height of document (html), then height of menu. Then, we substract menu height from document height, and result is content height. Same result we will apply to top position of content, to avoid overlaping.
Remove the "overflow-y: scroll;" attribute from your "html" selector in your style sheet.
edit:
I think if you are to use pure CSS you are going to have a scroll bar. I made a fiddle to show how to at least stop the nav from cutting off th top of the other divs. I used a
<div class="spaceTaker" >
that bumps the rest of the page down.
http://jsfiddle.net/Dtwigs/XRJ8n/
Edit2:
Try keeping all of the widths the same. But remove all of the heights where they are set to a percentage. The html element should have height: 100% but your tiles, etc. should not. Now put this jquery on your page.
$( function () {
var pHeight = $("html").height() - $("nav").height();
$(".tile").height(pHeight / 2);
});
Also make your nav position relative.
http://jsfiddle.net/Dtwigs/XRJ8n/

CSS How to set div height to 100% minus some pixels

I'm trying to design a web page these days that is a bit hard.
I have three main divs. First one for header, another for footer, and third one for main content. Header and footer must be fixed in top and bottom of the page. Their place mustn't change with resizing of browser window. Third div must be in the blank space between those divs. It can resize to fit the page with window resize.
Height of main div must exactly change, because I want to place a Google Maps in that div, so the height of this div is important.
I tried so many things, but they were not successful. Setting height of the div to 100%(while height of body and html is 100%, too) was not the answer. Using a table (with three rows, two rows with fixed height, one row with variable height, with height="100%") had some problems, too(in IE8, when I declared a doctype, the div in second row (with height:100%) didn't fit the cell anymore!).
Now I have no idea to do this work. What can I do?
Note: I prefer not to use CSS3, because compatibility with old browsers is important for me.
You could try something like this.
HTML
<div id="header"></div>
<div id="body"></div>
<div id="footer"></div>
CSS
#header {
height:50px;
width: 100%;
background: black;
position: fixed;
z-index: 1;
top: 0;
}
#body {
height:100%;
width: 100%;
background: #CCC;
position: absolute;
z-index: 0;
}
#footer {
height: 50px;
width: 100%;
background: #0CF;
position: fixed;
bottom: 0;
}
Here is a fiddle - http://jsfiddle.net/6M59T/
Use a set height for your header, and use sticky footer to keep your footer a set height and aligned to the bottom as well. The space in between should then always be the right height.
You should try the well known Clearfix hack to handle height issues, because you need to "clear" parents elements to get that full 100% height you need.
This is one of the shortcomings of css. You cannot accomplish what you want using just those three divs. You need to use additional divs to offset the height of your header and footer. Here is how to solve this:
<body style="height:100%; margin:0; padding:0;">
<div id="header" style="height:50px; position: relative; z-index: inherit; background-color:lightblue;"></div>
<div id="content" style="height:100%; margin:-50px 0 -70px 0; background-color:wheat">
<div id="header-offset" style="height:50px;"></div>
<div id="footer-offset" style="height:70px;"></div>
</div>
<div id="footer" style="height:70px; background-color:lightblue;"></div>
</body>

Trying to make the header height auto

My website here is a wordpress website but I believe the only thing I need to fix for an issue I'm having is the header height. The home page as a rotating banner which is 403px high and then all other pages have a header image of 303px high. I'm just trying to get the header height to be auto so the #container will automatically hug the bottom of the banner no matter it's height.
CSS
header { width: 960px; height: auto; margin: 0 auto; display: block;}
#container { width: 960px; margin: 20px auto; padding: 0 1.5em;}
What else should there be so the #container realizes that the header is there?
UPDATE:
NEW HTML
<div style="clear:both;"></div>
</div><!-- end of container-->
NEW CSS
#banner {
width: 960px; /* same with already defined */
height: 403px;
margin: 0 auto;
}
The only thinkg i did slightly differently was place the navigation under the header instead of the banner as it was underneath the banner of which i don't want. It looks the same however the doesn't seem to be doing anything differently then what I had previously. I still have that gap on the blog page under the banner.
I appreciate the help Zuul. I do think I have a bit more to go and then we can figure this out. Thanks!
The issue with the layout doesn't lay over the header tag, there are some elements positioned weirdly that are causing several problems:
This is a list of things to do in order to rectify the layout flow:
1)
Remove the <div id="banner"> from within the <nav id="main-navigation">.
The <nav id="main-navigation"> is set to height:70px and the slider is far taller than that.
Place it as a child of the <header> or after the <header> and before the <div id="container">.
e.g,
<header>...</header>
<div id="banner">...</div> <!-- here is better -->
<div id="container">...</div>
2)
After the first step, you can then remove from your #banner the following CSS:
REMOVE
#banner {
left: 50%;
margin-left: -480px;
position: absolute;
top: 69px;
width: 960px;
z-index: 1;
}
ADD
#banner {
width: 960px; /* same with already defined */
height: 403px;
margin: 0 auto;
}
3)
The step 01 and 02 should fix the #banner position along with the header height issue.
Now remains fixing the #container that contains floated elements and should be cleared at the end.
Here, your current class clearfix will not work, contains to many declarations, I would suggest:
<div id="container">
<div id="main">...</div>
<aside>...</aside>
<div style="clear:both;"></div>
</div>
Adding that new <div style="clear:both;"></div> at the very end of the #container will allow the float to be cleared and the document flow to resume normally.
EDITED
First phase is done, now the only thing you need to do is to remove the height from the #banner, and the gap will go away.
#banner {
width: 960px; /* keep this */
margin: 0 auto; /* keep this */
}
add a div with a style of clear:both just before your container div ends. This will allow to make the container div's height according to the contents inside it. You can make a class named clear and inside it you can put this style so that you can use this class anywhere in your website.

Resources