Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

bootstrap left nav overlap on mobile device

Posted on 2014-11-08
4
Medium Priority
?
783 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
The viewer will learn how to dynamically set the form action using jQuery.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

886 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