Solved

bootstrap left nav overlap on mobile device

Posted on 2014-11-08
4
571 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquery 10 20
replace link with jQuery 4 12
JS does not refresh 6 18
specific navigation button disappears on mobile devices 1 12
This article discusses four methods for overlaying images in a container on a web page
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.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 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