I want to give the container a 100% width using media queries, having the elements contained in a larger screen and not contained in a small one or vice versa. This code is just an example and it works with Bootstrap v4 alpha 6, but in the last release it doesn’t work anymore.
Anybody knows a solution?
@media screen and (max-width: 1000px) {
container {
width: 100%;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/js/bootstrap.bundle.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<nav class="navbar navbar-light bg-dark">
<a class="navbar-brand" href="#">Navbar</a>
</nav>
</div>
2
Answers
Here’s how you do it correctly without using the
container-fluid
class but instead putting everything inside into acontainer
(click the “run code snippet” button and expand to full screen to see that it’s indeed full width):Try the following code. It fit the
navbar
to the width of the page when the page width is less than500px
, else it has the normal effects of acontainer
class on your element. If you want change the page size and test it you can use jsFiddel demo.And if you want always the
navbar
fill full width of the page you can easily removecontainer
class from wrapper div: