Solved

bootstrap left nav overlap on mobile device

Posted on 2014-11-08
4
545 Views
Last Modified: 2014-12-15
I am EXTREMELY new to bootstrap.  I found code for a fixed left nav that works awesome on a desktop and laptop, but on a mobile device the body overlaps the left nav.  Any suggestions:

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-responsive.css" rel="stylesheet">  
</head>
<body>
<!-- left nav -->
  <div class="col-sm-2">
      <ul class="nav nav-stacked affix" id="sidebar">
        <li><a href="#">Hello</a></li>
        <li><a href="#">About Caroline</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">The Studio</a></li>
        <li><a href="#">Testimonials</a></li>
        <li><a href="#">Inspiration</a></li>
        <li><a href="#">Blog</a></li>
        <li><a href="#">Contact</a></li>
    </ul>
  </div>
<!-- end left nav -->

      <div class="col-sm-7">
          <div class="row"> <!-- body content here -->
                 blah blah
</div>
</div>
</body>

Open in new window

0
Comment
Question by:UniqueData
  • 2
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40452456
Post the real HTML not the encoded HTML or better yet a link to the page.
0
 
LVL 7

Author Comment

by:UniqueData
ID: 40455878
how odd.  The code looked fine the other day...

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-responsive.css" rel="stylesheet">  
</head>
<body>
<!-- left nav -->
  <div class="col-sm-2">
      <ul class="nav nav-stacked affix" id="sidebar">
        <li><a href="#">Hello</a></li>
        <li><a href="#">About Caroline</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">The Studio</a></li>
        <li><a href="#">Testimonials</a></li>
        <li><a href="#">Inspiration</a></li>
        <li><a href="#">Blog</a></li>
        <li><a href="#">Contact</a></li>
    </ul>
  </div>
<!-- end left nav -->

		<div class="col-sm-7">
			<div class="row"> 
				<!-- body content here -->
					blah blah
			</div>
		</div>
</body>

Open in new window

0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40455943
Anything that is fixed position is outside the natural page flow and the affix class isn't meant for use in the way you want.

If you want the fixed sidebar you will have to use some media queries to set the width.
This is just a default of 25% which would need increasing on very small screens

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<style>
.sidebar-fixed {
	width:25%;
}
</style>
</head>
<body>


<!-- left nav -->
  <div class="col-sm-2 col-xs-3">
      <ul class="sidebar-fixed affix" id="sidebar">
        <li><a href="#">Hello</a></li>
        <li><a href="#">About Caroline</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">The Studio</a></li>
        <li><a href="#">Testimonials</a></li>
        <li><a href="#">Inspiration</a></li>
        <li><a href="#">Blog</a></li>
        <li><a href="#">Contact</a></li>
    </ul>
  </div>
<!-- end left nav -->

		<div class="col-sm-10 col-xs-9">
				<!-- body content here -->
					blah blah

		</div>

</body>

Open in new window

0
 
LVL 7

Author Comment

by:UniqueData
ID: 40502060
that worked perfect.

sorry for the delay.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Find out what you should include to make the best professional email signature for your organization.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now