【发布时间】:2017-05-12 06:56:19
【问题描述】:
所以,基本上我想要做的是使用 javascript 来获取“body”的高度和“div class=main-container”的高度,然后如果主容器中的内容足够大,它会导致“主容器”高度大于我想要位置的“主体”高度:固定;将“.footer-section”上的属性更改为位置:相对;这样它就不会与内容重叠,而是从页面末尾“消失”,并且仅在您向下滚动时可见。 我不确定我是否在 javascript 或 CSS 中做错了什么,或者两者兼而有之?
我在这里拼凑了一个 jsfiddle:https://jsfiddle.net/udsv4t4y/1/
从这里开始是javascript:
function resizeFunction() {
var x = document.getElementsByTagName("body").offsetHeight;
var y = document.getElementsByClassName("main-container").offsetHeight;
var z = document.getElementsByClassName("footer-section");
if (x < y) {
z.className += "responsive";
} else {
z.className = "footer-section";
}
}
这是我正在使用的 HTML:
<body onresize="resizeFunction" onload="resizeFunction">
<div class="main-container">
<div class="row"></div>
<div class="col-12">
Lorem ipsum dolor sit amet, (cut out due to length)
</div>
<div class="row"></div>
<div class="col-12">
<div class="footer-section"></div>
</div>
</div>
</body>
和 CSS:
body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: auto;
font-family: "Tahoma", sans-serif;
font-size: 16px;
color: #454545;
background-color: #fff;
}
.main-container {
min-height: 100%;
width: 100%;
margin: 0;
}
.footer-section {
position: fixed;
bottom: 0;
height: 60px;
width: 100%;
background: #428cd9;
}
.footer-section.responsive {
position: relative;
bottom: 0;
height: 60px;
width: 100%;
background: #428cd9;
}
.row::after {
content: "";
clear: both;
display: block;
}
[class*="col-"] {
float: left;
}
.col-12 {width: 100%;}
【问题讨论】:
标签: javascript html css footer