admin管理员组文章数量:1296391
My Website here I have a page About Us due to lack of content we can not cover the plete height of the screen. And my footer starts floating in the air.. I tried doing it using min-height in a fieldset but unfortunately it works on my browser only as soon as I change my browser or try on other system the problem start again...
I have tried:
CSS
html,body{
min-height:100%;
height:100%;
}
[id]center_wrapper{
min-height:100%;
height:100%;
}
Javascript
var body1 = document.getElementsByTagName('body')[0];
console.log(body1);
body1.style.minHeight = screen.height;
body1.style.height = screen.height;
console.log(body1.style.minHeight);
jQuery
$('body').css('min-height', screen.height);
$('body').css('height', screen.height);
console.log(document.getElementsByTagName('body')[0].style.minHeight);
While using both jQuery and javascript Console Log it does shows 704px but it is not 704px.. I guess
it might be because change occurs after DOM is created..
Any help..
My Website here I have a page About Us due to lack of content we can not cover the plete height of the screen. And my footer starts floating in the air.. I tried doing it using min-height in a fieldset but unfortunately it works on my browser only as soon as I change my browser or try on other system the problem start again...
I have tried:
CSS
html,body{
min-height:100%;
height:100%;
}
[id]center_wrapper{
min-height:100%;
height:100%;
}
Javascript
var body1 = document.getElementsByTagName('body')[0];
console.log(body1);
body1.style.minHeight = screen.height;
body1.style.height = screen.height;
console.log(body1.style.minHeight);
jQuery
$('body').css('min-height', screen.height);
$('body').css('height', screen.height);
console.log(document.getElementsByTagName('body')[0].style.minHeight);
While using both jQuery and javascript Console Log it does shows 704px but it is not 704px.. I guess
it might be because change occurs after DOM is created..
Any help..
Share Improve this question edited Jun 15, 2013 at 4:47 Bhavik asked Jun 15, 2013 at 4:33 BhavikBhavik 4,9044 gold badges31 silver badges45 bronze badges5 Answers
Reset to default 5Thought I'd add an answer as I was searching for a solution to this problem and found one here, no javascript needed.
Code taken from the linked article:
<body>
<div id="wrapper">
<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
</div>
</body>
The HTML is basic with a wrapper directly inside the body.
html,
body {
margin:0;
padding:0;
height:100%;
}
#wrapper {
min-height:100%;
position:relative;
}
#header {
padding:10px;
background:#5ee;
}
#content {
padding:10px;
padding-bottom:80px; /* Height of the footer element */
}
#footer {
width:100%;
height:80px;
position:absolute;
bottom:0;
left:0;
background:#ee5;
}
The key points of the CSS is the wrapper's min-height:100% and the footer being absolutely positioned at the bottom inside it. You need to make sure the html and body elements are styled as specified as well, and give the content some space at the bottom as the footer will cover it.
The footer will stick to the bottom of the window with short content but be pushed beyond it with larger content.
From my point of view this is a process flow for your problem.
1. GET SCREEN HEIGHT.
var docheight = $(document).height();
alert(docheight);
2. THEN GET TAB MARGIN FROM TOP OF SCREEN BY USING.
var offset = $(this).offset();
var mydivlft = offset.left; // for LEFT margin from screen
var mydivtop = offset.top; // for TOP margin from screen
alert(mydivtop);
3. GET YOUR FOOTER HEIGHT BY USING ITs ID / CLASS.
var footerheight = $('#footer-info').height();
alert(footerheight);
4. NOW SET YOUR TAB VIEW HEIGHT
YOUR TABVIEW_HEIGHT = SCREEN_HEIGHT (minus) FOOTER_HEIGHT (minus) TAB_MARGIN_FROM_TOP
5. CODE
var x = mydivtop+footerheight
var newheight = docheight-x;
6. SET YOUR TAB VIEW HEIGHT
$('#tabs div').height(newheight);
Alright, since that didn't work... You have an html element style found in your div id "center_wrapper" it is contained within div id "title". Change the element style of min-height to 450 as shown below:
<fieldset id="center_wrapper" style="min-height: 450px;">
That should do the trick...
Sounds like what you really want is the footer pinned to the bottom of the browser window. Give this a try:
#footer-info {
position: absolute;
bottom: 0px;
}
Finally I made it..
What I did is:
1. Got the offset() and height() of the div I wanted to be at the bottom
2. Got the window height()
3. Finally using jQuery css property I got the margin necessary to keep it down
The Code is as:
$(function () {
var x = $('#footer-info').offset();
var z = $(window).height();
var y = $('#footer-info').height();
console.log(y);
if (z > x.top) {
var res = z - x.top - y;
console.log(res);
$('#footer-info').css('margin-top', res);
}
});
本文标签: javascripthow to make the minheight of body equal to screenheightStack Overflow
版权声明:本文标题:javascript - how to make the min-height of body equal to screen.height - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741636092a2389647.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论