How To Remove Gap After Footer In Bootstrap 4?
Below is my html code (live demo http://...) but the footer is not at the very bottom of the page, there is a gap after footer. How should I fix it? and what changes do I need in c
Solution 1:
Add width:100%
and position : absolute
and bottom: 0px
#footer {
width: 100%;
height: 60px;
background-color: #f5f5f5;
bottom: 0px;
position: absolute;
}
OUTPUT
position:fixed
would work just fine in this case
Solution 2:
You should use CSS's calc()
function in min-height
property. And wrap the .col-md-8
and .col-md-4
inside a parent div (.main-content
in my case). Like,
In HTML:
<div id="wrap">
<nav>...</nav>
<div class="main-content">
<div class="container-fluid">...</div>
</div>
<footer>...</footer>
</div>
In CSS:
.main-content {
min-height: calc(100vh - 136px); /* Total viewport height - (height of navbar + height of footer) */
}
Have a look at the snippet below (use full preview):
/* Sticky footer styles
-------------------------------------------------- */
html,
body {
height: 100%;
/* The html and body elements cannot have any padding or margin. */
}
/* Wrapper for page content to push down footer */
#wrap {}
.main-content {
min-height: calc(100vh - 136px);
}
/* Set the fixed height of the footer here */
#footer {
height: 60px;
background-color: #f5f5f5;
}
.navbar { margin-bottom: 20px; }
.card {
margin: 0 auto; /* Added */
float: none; /* Added */
margin-bottom: 10px; /* Added */
}
.table.no-border tr td, .table.no-border tr th {
border-width: 0;
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Cart</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Language" content="en-us">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/1061ab0407.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</head>
<body>
<div id="wrap">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Brand</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav ml-auto">
<li class="nav-item active dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</nav>
<div class="main-content">
<div class="container-fluid">
<!-- header -->
<div class="row">
<div class="col-md-8">
<div class="card bg-light mb-3">
<table class="table">
<thead>
<tr>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr>
<td>blah1</td>
<td>$12.10</td>
<td>
<form action="/new/cart/100" method="post" class="form-inline">
<input type="text" name="quantity" value="1" size="6" class="form-control input-sm">
<input type="hidden" name="item" value="2">
<input type="submit" value="Update" class="btn btn-primary btn-sm"> <input type="submit" name="remove" value="Remove" class="btn btn-danger btn-sm">
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-md-4">
<div class="card bg-light mb-3">
<h4 class="card-title">Cart summary</h4>
<ul class="list-group list-group-flush">
<li class="list-group-item">Total</li>
<li class="list-group-item">$17.60</li>
<li class="list-group-item">Coupon
<form action="/new/cart/100" method="post" class="form-inline">
<input type="text" name="coupon" value="" size="10" class="form-control input-sm">
<input type="submit" value="Update" class="btn btn-primary btn-sm">
</form></li>
</ul>
<a href="/coursecode1/slim/public/order" class="btn btn-default">Checkout</a>
<!-- /div -->
</div>
</div>
<!-- footer -->
</div>
</div>
</div>
<div id="footer">
<div class="container">
<center>All Rights Reserved.</center>
</div>
</div>
</body>
</html>
Hope this helps!
Solution 3:
#footer {
height: 60px;
background-color: #f5f5f5;
position: fixed;
bottom: 0;
}
Actually the elegant way is using Js or jQuery.
Solution 4:
Here is what that worked for me,
<footer>
<p class="text-center bg-dark text-white p-2 mb-0">Copyright 1990-2020 by Data. All Rights Reserved.</p>
</footer>
In the above code, the thing which is just creating difference is mb-0, In Bootstrap 4, mb stands for margin bottom. By writing mb-0 we are assigning as margin from bottom is 0dp.
Post a Comment for "How To Remove Gap After Footer In Bootstrap 4?"