To achieve the effect, you will need to use
@media(max-width: 767px) {
and @media(min-width: 768px) {
to make the necessary adjustments.
According to the link navbar-Fixed-top:
A body spacing is required
The fixed navbar will override other content, unless you purchase padding
to the top of the <body>
. Tip: By default navbar is 50px
.
Add to your code
body { padding-top: 70px; }
So this is what will help with your overlap problem.
I believe you want to turn the menu on the left side into a fixed navbar at the top with a button to make the "toggle".
To do so create the navbar, as in the link: http://getbootstrap.com/components/#navbar-Fixed-top should look something like (I added an attribute id
to avoid the css effect picking up on other "navbars", if any):
<div id="navbar" class="navbar navbar-inverse navbar-fixed-top" class="bs-example bs-navbar-top-example" data-example-id="navbar-fixed-to-top">
<div class="container-fluid navbar-collapse">
...
</div>
</div>
Create the .content
where your page content will be:
Using the @media
The min-width: 768px
would be the effect for larger screens, see that in the navbar I limited to 300px
and .content
I applied margin-left: 300px
, you can adjust this two as needed.
In the navbar-header
had an effect of float
which broke the appearance so I removed (only larger screens), the content
will need a left margin for content not to be below the "navbar".
@media (min-width: 768px) {
#navbar {
top: 0;
left: 0;
width: 300px;
height: 100%;
}
#navbar div.navbar-header {
float: none;
}
div.content {
margin-left: 300px;
}
}
As my comment at the beginning, we need to add body { padding-top: 70px; }
on the fixed navbar, then we will add only when the size is less than 768:
@media (max-width: 767px) {
body {
padding-top: 70px;
}
}
The result should be something like:
@media (min-width: 768px) {
#navbar {
top: 0;
left: 0;
width: 300px;
height: 100%;
}
#navbar div.navbar-header {
float: none;
}
div.content {
margin-left: 300px;
}
}
@media (max-width: 767px) {
body {
padding-top: 70px;
}
}
<link type="text/css" rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<div id="navbar" class="navbar navbar-inverse navbar-fixed-top" class="bs-example bs-navbar-top-example" data-example-id="navbar-fixed-to-top">
<div class="container-fluid navbar-collapse">
<div class="navbar-header">
<button aria-expanded="false" type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-6">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<div aria-expanded="false" class="navbar-collapse collapse" id="bs-example-navbar-collapse-6">
<ul class="nav">
<li><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
</ul>
</div>
</div>
</div>
<div class="content">
1<br>2<br>3<br>4<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>
a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>
a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>
a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>
a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>
a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>
a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>a<br>
</div>
You didn’t have to delete the original question and redo it. You just had to edit the other one. It was very difficult to find your profile and to know what had happened.
– Guilherme Nascimento
Funny Luiz, I’m sorry for the sincerity, but in your other question I edited it for you, moved the code, adjusted the examples, put the right tags in the question, and you delete the question and still open a new one using the wrong tag and putting a title similar to the old one. Does the FOLLOWING, moves the Bootply code to the Stackoverflow Snippet (edit your question for this), external links may eventually crash, which would render the question invalid for possible answers (just like I did in editing your other question).
– Guilherme Nascimento
@Guilhermenascimento sorry, I was a little lost on this site, but I think I already found myself! This my code is working the way I want for desktop and tablet, just not working for mobile! just need to adjust it for mobile!
– Luciano Oliveira Lima
I had already understood since the other question, the problem is that I avoid to answer something that is not clear soon in the question pq otherwise it is as if I answered something that was not asked :) tomorrow morning if no one has answered I answer, because now I am on the mobile, It gets tough, good night man
– Guilherme Nascimento
@Guilhermenascimento just have to thank you! Thank you! Good night! I’ll be waiting for your answer!
– Luciano Oliveira Lima
@Guilhermenascimento can help me friend?
– Luciano Oliveira Lima