100% height is making div overflow - css

this question is probably pretty common, as i've been going over answers here for the past 3 hours. and still, no success.
I have a parent html which takes 100% height of the page. the body takes also 100% of the page.
In the body element i have 3 divs. i have the 3rd and last one, to take the rest of the page and leave no whitespace after it (which it does now).
tried height: 100%; on the last div and overflow: hidden; on the body element. this just stratches my page and removes the scroll bar (but the website still scrolls O_O ).
please help.
edit: it seems the question itself isn't clear.
I want the last div to take the rest of the page height to the end of it.
#div1{
max-height: 150px;
}
#div2{
max-height: 150px;
}
#div3{
padding: 10px 0;
margin: 0;
height: 100%;
}
all nested inside a body element which is nested inside html element.
I also have hidden info which is required to show when i click.. so i do need the page to stratch, if any more info is added to the page (hiding overflow on the entire document is going to be a problem than)

Maybe try this code:
<body>
<div id="container" style="height: 100%"; overflow="hidden">
<div>
asas
</div>
<div>
sdsd
</div>
<div>
wewe
</div>
</div>
</body>

Related

UI-Router: Height:100% on body element ignoring nested view height

I'm building an angular application that frequently uses nested views. Certain views, however, are taller than the other elements on the page and end up extending well beyond the end of the parent view.
I'm using Ryan Fait's Sticky Footer so I have a wrapper around a containing div set to height:100% and I would have expected the page to just adapt and move the footer to the bottom of the nested view however I'm seeing the style elements of the footer border and background-color are remaining at end of the parent div while the content of the footer is being pushed to the end of the nested div.
Including an image as I'm struggling with getting the language exact:
I'm really looking for any solution from fixing the css to something that seems hackier like changing the footer or using ng-if/ng-class on certain pages. I'm imagining I'm misunderstanding something about CSS/UI-Router but I can't really track it.
The code isn't really interesting but here is it?
CODE
.wrapper {
min-height: 100%;
margin-bottom: -50px;
}
.push {
height: 50px;
}
.footer {
display: block;
height: 50px;
}
.nested {
max-height: 500px;
}
<body>
<div class="wrapper">
<div>
<h1>Some text</h1>
<ui-view class="nested"></ui-view>
</div>
<div class="push"></div>
</div>
<footer class="footer">
<span>some copy</span>
</footer>
</body>
If you use percentage values for height (i.e. a relative height), the parent element heights have to be defined too. In your case you also need height: 100% on body and html, like
html, body {
height: 100%;
}

ng-view height issue in angularJS?

I am using ng-view, to display view based on the routeProvider. In my application, ng-view added like this
<div ng-view style="height: 100%; background:#000000;"></div>.
In one of my views, there is a left navigation, which should displayed 100% in height in the browser. For some reason, left view navigation height is created only based upon the data. That is if data is more, height is incremented.
I am not sure, why height is not incremented even though I set hieght=100%, here is the code of Left navigation
<div class="options1">
<div class="options">
<a ng-repeat="name in list" >{{name.name}}</a>
</div>
</div >
.options {
background:#FFFFFF;
min-height: 190px;
width:10em;
height:100%;
border: 1px solid red;
color:#FFFFFF;
}
.options1 {
min-height:100%;
background:red;
width:15em;
}`
I got it working, it is an CSS issue.
I have added this into CSS,
html, body { height: 100%; width: 100%; margin: 0; }.
Here is the link for more details
Css height in percent not working
use Viewport Height, it's absolutely
style="height: 100vh;"
This isn't an angularJS issue, but most likely a CSS styling issue. If it is so, then you need to investigate it as such - there isn't much information to go on in your question, but a div stretches to 100% of it's parent, so you need to make sure that is happening. Also, positioning is very important.
If this is the case, there is no need to duplicate an answer - see if this other SO answer is of any help.
I think css:
.ng-scope{
height: 100% !important;
}
On my computer it works correctly,
for reference only

overflow: hidden on div and body, different behavior

Given this html:
<body>
<div id="a"></div>
<div id="b"></div>
</body>
I want #b to fill all the remaining vertical space of its container block, I began with this:
body {
height: 500px;
width: 500px;
overflow: hidden;
}
#a {
height: 100px;
width: 100px;
}
#b {
height: 100%;
width: 100%;
}
So #b is 100% height, which means that it is taking the height of its parent container block, which is 500px, the problem is that the overflow: hidden; seems to not work, #b is not clipped.
On the other hand, if I wrap #a and #b with another div with the same properties as body above I have the desired result:
#wrap {
height: 500px;
width: 500px;
overflow: hidden;
}
#a {
height: 100px;
width: 100px;
}
#b {
height: 100%;
width: 100%;
}
with this html of course:
<body>
<div id="wrap">
<div id="a"></div>
<div id="b"></div>
</div>
</body>
My question is why div and body seems to have different behaviors with the same properties? and is there any way to get the same effect without the wrapper?
To illustrate the question I have created two jsFiddles:
jsFiddle with body tag as wrapper: http://jsfiddle.net/3AMtG/
jsFiddle with div tag as wrapper: http://jsfiddle.net/2QWn3/
Two jsFiddles with the same properties yield different results. Why is that?
The overflow property has certain special behaviors specific to HTML's html and body elements, which are described in the CSS2.1 spec. These special cases are in place to accommodate changing overflow settings on the entire page in normal circumstances so authors simply need to set it on either html or body, but not both.
In this case, when you apply overflow: hidden to body, it actually affects the viewport instead of body (you can see this by resizing the preview pane to make it shorter — no scrollbars will appear on the preview pane itself). This causes #b to overflow the body normally even though you give it a fixed height that's less than the sum of #a and #b. In other words, it's as though you never set it on the body in the first place.
If you set overflow to something other than visible on html, though, this causes the viewport to use the value given to html instead of body, thereby leaving the declaration on body unaffected and allowing it to behave the same way as the wrapper:
html {
overflow: auto;
}
body {
height: 500px;
width: 500px;
overflow: hidden;
}
jsFiddle preview
body and div have totally different of them. In my daily working, I like constructing my code like this.
<div class='xxx-ctn'>
<div class='xxx-inner'>
<div class='data-wrapper'>
[p|ul|ol|h1-h6|article|section].....
</div>
</div>
</div>
Okey, I missing your founding, but I think this is a good coding habbit.
Body element is considered as main parent element inside which other elements that are displayed within the browser window resides therefore, width and height property is not applicable onto it. According to the best practices it is better to create a div container like #wrapper that you did in your second example.

Chrome: overflow:auto + margin:auto fails to layout correctly sometimes

I'm trying to layout a page which has anchor elements that I would like on a new line and centered. However these blocks are inside of <p> elements which are beside floating images.
Right:
http://test.sunnysidemarket.ca/right.jpg
Wrong:
http://test.sunnysidemarket.ca/wrong.jpg
So basically I have:
HTML:
<div class="content">
<div>
<img src="..." width="276" height="207" />
</div>
<div class="body">
<p>
...
<a class="mediaset" href="...">Link</a>
</p>
</div>
</div>
CSS:
.content img {
float: right;
}
a.mediaset {
margin: 0 auto;
width: 220px;
display: block;
overflow: auto;
}
Or what you can see in the jsfiddle: http://jsfiddle.net/CVkFw/
The issue is intermittent, sometimes it happens, sometimes it doesn't. What it appears to me to be is a bug in chrome where the overflow and margin properties are calculated but when the floating content loads, sometimes the browser doesn't layout the elements again.
There are ways of solving this using jQuery and modifying my HTML but I would really love to solve this with CSS if at all possible.
My best guess is that this erratic behavior is caused by overflow: visible applied in global.styles.css. The problem:
.node-article .field-name-body,
.node-synced-facebook-content .field-name-body {
overflow: visible;
}
I'm offering this suggestion because when I add this CSS override for overflow: hidden, that component appears to load "more solidly". The fix:
.node-article .field-name-body,
.node-synced-facebook-content .field-name-body {
overflow: hidden;
}
The selector itself might need to be adjusted depending on what it is intended to affect. (I'm obviously not that familiar your page's css code.) Hopefully this points you in the right direction though!

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>

Resources