Reputation: 3008
Actually, I have two footers with dynamic content.That why I am using jquery to make sub-footer and main-footer sticky. Now footer sticky is working, but on window resize, the height of main-footer increasing. Please see script. I think, I have issue with script. I have added script at bottom of my code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../../../favicon.ico">
<title>Sticky Footer Navbar Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="sticky-footer-navbar.css" rel="stylesheet">
<style>
html {
position: relative;
height: 100%;
}
body {
/* Margin bottom by footer height */
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
background-color:#000;
text-align:center;
color:#fff;
}
.footer-bottom{
padding:3px 0;
position:absolute;
bottom:0;
background-color:green;
text-align:center;
width:100%;
}
</style>
</head>
<body class="page-body">
<!-- Fixed navbar -->
<!-- Fixed navbar -->
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="#">Fixed navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline mt-2 mt-md-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
<!--[ container ] -->
<div class="container">
content here
</div>
<!--[ footer ] -->
<div class="footer">
<p>Place sticky footer content here.</p>
</div>
<div class="footer-bottom">
<p>footer Bottom</p>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script>
<script>
function sizing(){
var completeFooter = $(".footer").height() + $(".footer-bottom").height();
$(".footer").css("height", completeFooter);
$(".page-body").css("margin-bottom", completeFooter);
}
$(document).ready(sizing);
$(window).resize(sizing);
</script>
</body>
</html>
Upvotes: 0
Views: 413
Reputation: 8625
EDIT based on comment:
bottom: 46px;
--> your static footer's height
Snippet below:
html {
position: relative;
height: 100%;
}
body {
/* Margin bottom by footer height */
}
.footer {
position: absolute;
bottom:46px;
width: 100%;
/* Set the fixed height of the footer here */
background-color: #000;
text-align: center;
color: #fff;
}
.footer-bottom {
padding: 3px 0;
position: absolute;
bottom: 0;
background-color: green;
text-align: center;
width: 100%;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
<body class="page-body">
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="#">Fixed navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline mt-2 mt-md-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
<!--[ container ] -->
<div class="container">
content here
</div>
<!--[ footer ] -->
<div class="footer">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste neque deserunt alias, hic incidunt sequi reiciendis, quis nobis accusantium, quod iure, ipsum soluta architecto maxime quas veritatis sint animi repellat!</p>
</div>
<div class="footer-bottom">
<p>footer Bottom</p>
</div>
Upvotes: 1