I'm very new to JavaScript and am trying to use it to give my footer a margin. I need the footer to be flush against the bottom of my content, which has a dynamic height (when the browser is resized, the content gets appropriately larger/smaller to fit text). Here's my code:
function footermargin() {
var height = document.getElementById('content').offsetHeight;
document.getElementById("footer").style.marginTop = "height";
}
body {
margin: 0;
}
#content {
position: absolute;
z-index: -1000;
margin-top: 35px;
width: 100%;
margin-left: 0;
margin-right: 0;
height: auto;
background-color: blue;
color: white;
}
#footer {
color: white;
background-color: #134;
margin-top: auto;
z-index: -9999999;
position: static;
width: 100%;
-webkit-box-shadow: inset 0px 10px 19px 0px rgba(0, 0, 0, 1);
-moz-box-shadow: inset 0px 10px 19px 0px rgba(0, 0, 0, 1);
box-shadow: inset 0px 10px 19px 0px rgba(0, 0, 0, 1);
}
<body>
<div id="content">this is the content of the webpage. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sed lacus libero. Duis tristique fringilla purus, a blandit arcu lacinia in. Phasellus quis lobortis justo. Proin fringilla nulla nisl, at fringilla metus maximus quis. Donec ultricies fringilla felis, eget rhoncus neque mollis ac. Aliquam porta, odio sed ornare consequat, enim neque pharetra enim, sit amet luctus turpis odio id erat. Vivamus porttitor egestas nunc a maximus. Cras maximus et erat nec tincidunt. Nam eget lectus a lorem rutrum fringilla sit amet in lacus. Vestibulum nec pharetra lectus. Proin non quam quis mauris tempor varius ac eget purus. Quisque luctus leo ut libero sollicitudin, ac fringilla tellus lacinia.
</div>
<div id="footer">this is the footer of the webpage. I need this flush against the bottom of the content without using specific margins.</div>
<script>
function footermargin() {
var height = document.getElementById('content').offsetHeight;
document.getElementById("footer").style.marginTop = "height";
}
</script>
</body>